Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя TheScrasse

Автор TheScrasse, история, 5 часов назад, По-английски

All the Polygon materials (including the official implementations of all the problems) are here.

2019A - Max Plus Size

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Solution

2019B - All Pairs Segments

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Solution

2018A - Cards Partition

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Hint 4
Solution

2018B - Speedbreaker

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Solution

2018C - Tree Pruning

Author: wksni
Preparation: TheScrasse

Hint 1
Hint 2
Solution

2018D - Max Plus Min Plus Size

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Solution

2018E1 - Complex Segments (Easy Version), 2018E2 - Complex Segments (Hard Version)

Authors: lorenzoferrari, TheScrasse
Full solution: Flamire
Preparation: franv, lorenzoferrari

Hint 1
Hint 2
Hint 3
Hint 4
Solution

2018F1 - Speedbreaker Counting (Easy Version), 2018F2 - Speedbreaker Counting (Medium Version), 2018F3 - Speedbreaker Counting (Hard Version)

Author: TheScrasse
Full solution: Flamire
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Solution
Разбор задач Codeforces Round 975 (Div. 1)
Разбор задач Codeforces Round 975 (Div. 2)
  • Проголосовать: нравится
  • +68
  • Проголосовать: не нравится

»
5 часов назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

1 minute late editorial?

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

:)))) Too fast

»
5 часов назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

E was such a good problem, great problemset. im so mad i didnt get C earlier though

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

very interesting problems!!

»
5 часов назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

The goddamn C...

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

so fast :O

anyway, good songs :D

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thank you so much for the great contest! I loved the problems!

»
5 часов назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Is it just me or was this Div 2, little too difficult?

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i think this is one of the easier ones recently. a and b are pretty simple and c seems hard (atleast it seemed to me) but is actually fairly simple. the rest are pretty standard div2 problems imo

    • »
      »
      »
      5 часов назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      It's just me then I guess. Tbh, I couldn't even solve one lol. I did get the basic idea but could not solve them completely, in first and second question. Anyways thanks for the reply, mate!

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i think its a bit easier than other div2 , C usually is harder i find it a bit easy i came up with the idea for it very fast but took me some time to fully solve it and b was easy but i spent a lot of time understanding what they want like it took me 40 min just to understand the problem and solve it in like 15min

»
5 часов назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

To solve the third problem [2018A cards partition], can we use the binary search?

if yes then how to implement the checker function that this size of deck is possible or not

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I tried but mine didn't work

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    i thinking no, because the checker is no montonic fuction

    thinking in the primes number and k=0, the 6 can be divide, 7 no, and 8 yes. So the binary search can fail.

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I think we can't do binary search on no.of decks

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    consider how you would make the decks, you would put all the cards with the highest frequency first, and then just greedily put all the cards on top of the lowest deck that you own currently, without making any new decks. then in the end if the last "row" you filled wasn't completely filled, you can try filling it with the k coins you have. you can do that if (sum)%x<=k , where x is the size youre checking. i didnt do it with bs, since i couldnt prove that if x doesnt work then x+1 surely wont work. also you have to check that the partition that you made actually uses all cards, you can check this by seeing if the amount of decks you would have would be atleast the frequency of the most frequent card. i hope i explained it well, if its not clear, just ask. also you can check my solution for details, but its very simple

  • »
    »
    5 часов назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    I tried but got WA on pretest 4, I think search space is not monotonic

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    A binary search on all numbers from $$$1$$$ to $$$n$$$ doesn't work, because the function isn't monotonic, so if some deck size fails, it's still possible for a bigger one to succeed. Consider a case where you have $$$n=5$$$, $$$k=0$$$, and $$$1$$$ card of each type. Clearly, the only possible deck sizes are $$$1$$$ and $$$5$$$, while $$$2$$$, $$$3$$$ and $$$4$$$ fail, but $$$5>4$$$.

    It might be possible to do a binary search on all numbers that divide at least one possible number of cards you can get. I'm not sure about that. In any case, as of now, I'm not aware of any reasonably fast checker function that isn't $$$O(1)$$$ (or easily possible to turn into $$$O(1)$$$ by some precomputation), so this probably isn't a great way to think about the problem.

  • »
    »
    2 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i tried but wrong 283276768

»
5 часов назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

How much practice do i need i was stuck at B completely.

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    its an complete observation problem.Second test case is enough to get the answer try to dry run it, you will get the answer

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

E1,O(n * sqrt(n) * log^2(n)) got a TLE......sad

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How to implement E.

  • »
    »
    5 часов назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    here. if you have any questions, just ask

    • »
      »
      »
      5 часов назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      the only thing i don't understand is how maxwin affects the answer. I was able to implement everything else.

      • »
        »
        »
        »
        5 часов назад, # ^ |
        Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

        maxwin[i] is the maximum depth you can reach if you start going down from the i-th vertex. then when checking for a certain depth x, if maxwin[i] is smaller than x, then i must be destroyed, because the i-th vertex can never become a leaf with depth x, and neither can any node in it's subtree, so the entire subtree must be destroyed, since i counted all the vertices by themselves i just remove a vertex one by one

        • »
          »
          »
          »
          »
          4 часа назад, # ^ |
            Проголосовать: нравится +3 Проголосовать: не нравится

          yes yes brilliant thank you. I was trying to do something like this with prefix sums as well but failed miserably.

»
5 часов назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

today's contest just ruined my day (though contest was good)... My submission on C 283251847 is the biggest blunder i had done till now... if i did not tried the binary search && just run a loop my code would be accepted && I might be Cyan today...

when i firstly start to solve this C.. i go for nlogn approach... then make the function 'f' .. but i did not notice function is literally O(1) .. so I could run a O(n) loop...

when i find this 1 minute after contest, I realize this CP is not for me...

(apologies for my poor english)..

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The intervals in the editorial of F should be $$$[i - a_i + 1, i + a_i - 1]$$$?

»
5 часов назад, # |
Rev. 9   Проголосовать: нравится +9 Проголосовать: не нравится

An alternative solution for Speedbreaker (Div2D):

There are 4 cases:

  1. $$$a_0 < n$$$ and $$$a_{n-1} < n$$$: no solution is possible.
  2. $$$a_0 \geq n$$$ and $$$a_{n-1} < n$$$: This means that $$$a_0$$$ must be the last element that is conquered. We now check how many solutions exist in the interval $$$[1, n-1]$$$.
  3. $$$a_0 < n$$$ and $$$a_{n-1} \geq n$$$: Similar to second case.
  4. $$$a_0 \geq n$$$ and $$$a_{n-1} \geq n$$$: We now want to check if $$$a_0$$$ and $$$a_{n-1}$$$ are valid solutions. $$$a_0$$$ is a valid solution only if we can conquer every city going from left to right. To check if $$$a_0$$$ is a valid solution, create a segment tree $$$b$$$ with $$$b_i = a_i - i$$$. Now do a query on the range $$$[0, n-1]$$$. $$$a_0$$$ is a valid starting city if and only if the result of the query $$$\geq 1$$$. For checking if $$$a_{n-1}$$$ is a valid starting city, do something similar. After that, count the number solutions in the range $$$[1, n-2]$$$.

Submission: 283247155

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Wasn't div2 E a lot easier for its position?

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

C was tooo gorgeous... Gave it the attempt of my life on Codeforces... Learnt a lot, it was like an adventure... Thank you contest×codeforces

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    literally had the same experience with C, spent like an hour on it and finally got the perfect solution.

    also is your profile picture a reference to the AMV tan(x) by lolligerjor?

    • »
      »
      »
      3 часа назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Ummm, No, didn't know that such thing existed, but my good name is Tanishq, it kinda sounds like TanX, maybe...Yes!

»
5 часов назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

For div2 E i used ternary search on depth...and got wrong answer on test 3.i can not find any wrong case.can anyone hep me 283252293? update: may be this problem can't be solve using ternary search. i got a case

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

woah too fast (:

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Felt like DIV2B was harder than DIV2C :)

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Oh wow, my solution to F is completely different. The canonical strategy that I use for an array with a marked interval of possible starting cities is to always go to the city with the shortest deadline and break ties by going left. It seems that the resulting dp is very different (and in particular I don't need to use any division)

»
4 часа назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Obligatory "thanks mr Radewoosh" comment.

div1E is https://codeforces.me/blog/entry/61331

»
4 часа назад, # |
  Проголосовать: нравится -9 Проголосовать: не нравится

Why this code is a incorrect !! My intuition was first find maximum element across the array and then if n is even — n/2 and if n is odd — ((n+1)/2)?!

int main() {
    int t;
    cin >> t; 
    while (t--){
        int n;
        cin>>n;
        vector<int>arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        int max_value= *max_element(arr.begin(),arr.end());
        if(n==3){
            cout<<arr[0]+((n+1)/2)<<endl;
        }
        if(n%2==0){
            cout<<(n/2)+max_value<<endl;
        }
        else if (n!=3){
            cout<<((n+1)/2)+max_value<<endl;
        }
    }
 
    return 0;
}
  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    First of all, your n == 3 case should be reconsidered as on test cases:

    1
    3
    1 2 3
    

    Your code says 3 but the answer is max_ele(3) + 2 = 5 As the 1 2 3 you can colour 3 and 1 red having 2 red elements + max_ele(3) will give optimal answer as 5. Moreover, you have to consider the max element being in an odd place having all odd indexes counted elements, or being in an even place having all even indexes counted elements.

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      what about this solution-

      #include<bits/stdc++.h>
      using namespace std;
      typedef long long ll;
      
      int main() {
          int t;
          cin >> t; 
          while (t--) {
              int n;
              cin >> n;
              vector<int> arr(n);
              for (int i = 0; i < n; i++) {
                  cin >> arr[i];
              }
              int max_value = *max_element(arr.begin(), arr.end());
              
              if (n % 2 == 0) {
                  cout << (n / 2) + max_value << endl;
              } else {
                  cout << ((n + 1) / 2) + max_value << endl;
              }
          }
      
          return 0;
      }
      
      
»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It's shocking that so many people in Div1 solved problem C.

  • »
    »
    4 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    i found D1C to be the easiest div1 problem today, looking at my friendlist, most people had the same feeling. It was obvious to me what to do upon reading the problem. Same for D too, I took less time to mindsolve CD combined than either of AB

    • »
      »
      »
      4 часа назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      D might be *2200,but C is sure under 1900.

    • »
      »
      »
      3 часа назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      I am interested to know your opinion on this. After reading your comment, I spent some more time on problem C, unfortunately I still can't come up with the solution. I haven't looked at the editorial but so far my idea is to consider iterating on the levels of the tree and taking the minimum and for a particular level the answer is N-number of distinct vertices on the path from the root to all the vertices on the current level(I actually figured all this in about ten minutes but I can't think of a way to calculate this in O(n), maybe LCA/inclusion exclusion to avoid double counting I don't know). What do you think one should ideally do in such case? Try for more time or just look at the editorial and be done with it?

      Also, I solved DIV1 A in about 30 minutes and got the idea even fairly quick and spent time only to fix a stupid typo. However, if I didn't already know the fact that we only need to know the max element and total sum to figure out if we can arrange the cards, then I don't think I would have been able to solve the problem. So, for DIV1A I would recommend someone to look at the editorial quite early if they weren't able to solve it. So, my general question is how long do you think should one spend time trying to solve a problem before looking at editorial and what was your strategy when you were at specialist/expert level ?

      • »
        »
        »
        »
        109 минут назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

        you are close on C, you just overcomplicated the latter part. Try to think of when a vertex will be deleted instead of its opposite.

        As for when I used to read editorials, it somewhat depends on my progress. If i felt I was close to the answer, I would hold off / read a bit after long time. Otherwise, if i did not make substantial progress, I would read after say 30mins — 1 hour (now its more ofcourse)

        • »
          »
          »
          »
          »
          60 минут назад, # ^ |
          Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

          Thanks for the response! With your hint for C, I managed to solve it myself. I would have solved it in 30-40 min I guess if I thought of this:( Is there a way to count the answer if you look at it my initial way(counting the distinct vertices among all the paths from root to all the vertices at the current level)? Assume if that was what you thought first, Is there any way to recognize that the other way of looking at it is easier/will lead to solution or once you are stuck you just simply switch to looking at when the vertex will be deleted instead of opposite? Asking because I kind of get stuck on one approach like this and fail to solve many solvable problems and would love to get better.

          • »
            »
            »
            »
            »
            »
            50 минут назад, # ^ |
              Проголосовать: нравится +2 Проголосовать: не нравится

            Is there a way to count the answer if you look at it my initial way(counting the distinct vertices among all the paths from root to all the vertices at the current level

            yes, but it will end up being the same thing. We want to charactertize such vertices to easily count them. Its not hard to see that you want to count vertices that satisfy dep_u <= k and max_dep_in_subtree_u >= k

            So, for all k in range [dep_u, max_dep_in_subtree_u], increase the count of saved vertices by 1.

»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can someone please tell me what's wrong with this soln for Div2-B? it gave WA on pretest 9

#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int n,q;
        cin>>n>>q;
        vector<int> v(n);
        vector<long long> queries(q);

        for(auto &x:v) cin>>x;
        for(auto &x:queries) cin>>x;

        map<long long,int> mp;

        for(int i=0; i<n; i++){
            long long cnt = 0;  // number of segments this point is part of

            if(i==0 || i==n-1) cnt += n-1;
            else{
                cnt += (n-1+(i*(n-1-i)));
            }

            if(mp.find(cnt)!=mp.end()) mp[cnt]++;
            else mp[cnt]=1;
        }

        for(int i=0; i<n-1; i++){    // considering the points that lie on the axis apart from the ones in the array
            long long cnt = (i+1)*(n-1-i);

            if((v[i+1]-v[i]-1)>0){
                if(mp.find(cnt)!=mp.end()) mp[cnt]+=(v[i+1]-v[i]-1);
                else mp[cnt]=(v[i+1]-v[i]-1);
            }

        }

        for(int i=0; i<q; i++){
            if(mp.find(queries[i])!=mp.end()) cout<<mp[queries[i]]<<" ";
            else cout<<0<<" ";
        }
        cout<<endl;


    }

    return 0;
}
  • »
    »
    3 часа назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    maybe integer overflow in the line cnt += (n-1+(i*(n-1-i))); You have taken n and i as int.

»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

My O(n^5) solution (with small constant) passed F1. However it's hard to optimize to O(n^4) or better (Because I solved d1B by a suboptimal solution, which mislead my thinking of F1)

»
113 минут назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

For F you don't really have to think about paths at all, inclusion-exclusion on the arrays is enough (submission 283272424, ignore the unused variable).

Idea one: it's always sufficient to take the "working" interval first.

Idea two: to count the number of arrays of length $$$k$$$ with elements in $$$[1,n]$$$ and every index works, one only needs to make sure the endpoints work. You can just lower bound the elements for a count of

$$$ \frac{\left(n-\left\lfloor\frac{k}{2}\right\rfloor\right)!\left(n-\left\lceil\frac{k}{2}\right\rceil\right)!}{(n-k)!^2} $$$

Now iterate over $$$k$$$. Count the above and consider how to count extensions to arrays of length $$$n$$$ that do not break any of the elements that were supposed to work. You can do this with PIE; to get extensions of length $$$i$$$ get extensions of length $$$i-1$$$ and extend them on either side, then subtract out extensions of length $$$i-2$$$ where you can take the next two elements in either order. (see my solution for the push dp)

Now you have

$$$ ans[k] = \sum_{\text{arrays $$$a$$$}}\#\{\text{intervals $$$I$$$ of working indices in $$$a$$$ with $$$|I|=k$$$}\} $$$

Idea three. the PIE to finish is by subtracting out

$$$\#\{\text{intervals $$$I$$$ of working indices in $$$a$$$ with $$$|I|=k$$$}\}$$$

for each $$$a$$$ with a working interval larger than $$$k$$$. If you know the size of the working interval, you can count this.

»
53 минуты назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

too fast!!

»
6 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

D is a tremendous problem