Please read the new rule regarding the restriction on the use of AI tools. ×

TheScrasse's blog

By TheScrasse, history, 3 hours ago, In English

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
  • Vote: I like it
  • +59
  • Vote: I do not like it

»
3 hours ago, # |
  Vote: I like it +2 Vote: I do not like it

1 minute late editorial?

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

:)))) Too fast

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

very interesting problems!!

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

The goddamn C...

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

so fast :O

anyway, good songs :D

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it +9 Vote: I do not like it

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

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      3 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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!

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

»
3 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    I tried but mine didn't work

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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.

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

  • »
    »
    3 hours ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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.

»
3 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

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

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

How to implement E.

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    here. if you have any questions, just ask

    • »
      »
      »
      3 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

      • »
        »
        »
        »
        3 hours ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        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

        • »
          »
          »
          »
          »
          2 hours ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

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

»
3 hours ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

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)..

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
Rev. 9   Vote: I like it +6 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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?

    • »
      »
      »
      71 minute(s) ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

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

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

woah too fast (:

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Felt like DIV2B was harder than DIV2C :)

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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)

»
2 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Obligatory "thanks mr Radewoosh" comment.

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

»
2 hours ago, # |
  Vote: I like it -6 Vote: I do not like it

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;
}
  • »
    »
    105 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      89 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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;
      }
      
      
      • »
        »
        »
        »
        80 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        1
        5
        1 5 2 3 4
        

        what do you think the answer should be?

»
106 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    93 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      91 minute(s) ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      23 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 ?

»
67 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

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;
}
  • »
    »
    51 minute(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

»
37 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

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)