Kogut_Ivan's blog

By Kogut_Ivan, 4 months ago, In English

We hope you enjoyed the contest! Thank you for participating! This is our third official round on Codeforces, so we would be happy to hear your feedback in the comments and in the mini-survey below.

How did you like the contest?
Which problems did you like (you can choose multiple)?
Which problems did you not like (you can choose multiple)?

2184A - Social Experiment

Idea: fstilus; developer: fstilus

Hint
Editorial
Solution

2184B - Hourglass

Idea: fstilus; developer: fstilus

Hint
Editorial
Solution

2184C - Huge Pile

Idea: Friendiks; developer: fstilus

Hint 1
Hint 2
Editorial
Solution

2184D - Unfair Game

Idea: Friendiks; developer: Friendiks

Hint 1
Hint 2
Hint 3
Editorial
Solution
Bonus

2184E - Exquisite Array

Idea: fstilus; developer: fstilus

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Editorial
Solution

2184F - Cherry Tree

Idea: gravitsapa; developer: gravitsapa

Hints for the first method
Hints for the second method
Editorial
Solution 1
Solution 2

2184G - Nastiness of Segments

Idea: Friendiks; developer: Friendiks

Hint 1
Hint 2
Hint 3
Hint 4
Editorial
Solution
  • Vote: I like it
  • +30
  • Vote: I do not like it

»
4 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

Bad contest for me, I struggled on B!

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    For me too, I haven't solved a single problem

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I solved C but couldn't solve B

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

      hey !

      could you please explain the problem -C and give the code for the same .

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

        Hello, I can share my method for C if you wish to go through it.

        First, I noticed that to get any pile size k in one pile division, the current pile size must be either 2k-1, 2k or 2k+1. So the current pile size must lie between 2k-1 and 2k+1, inclusive. We can then set a range, such that if it consists of a number, it is possible to get 2k-1, 2k, or 2k+1. This would be 2(2k-1)-1 to 2(2k+1)+1, inclusive.

        Using this, we can set a range of what the current pile size should be for it to be possible to get k. We can keep increasing the range as long as the lower limit is less than n+1 and also increase a variable i per iteration.

        If at any point of time, the starting pile size (n) falls into the range, the number of pile divisions taken is i. If it doesn't fall in the range while the loop is going on, it is not possible.

        Edge cases can be handled separately.

        This is my understanding, hope it helps. I can attach my code for reference if you want it.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yeah same got idea for c but took time for B lol

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yeah same struggle on b

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yeah b felt kinda hard as well i cant lie. but honestly failing d is probably the biggest sign for me that this was a hard contest because im strongest at binary problems

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

    i find A and B quite easy. C's a bit of a struggle for me tho

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

    SAME

»
4 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

E can actually be addressed in O(n) easily.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    How?

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Each merge requires information only from the two sides of a component, so we can dynamically maintain them.

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it +10 Vote: I do not like it

      Using stacks approach

      • Build the absolute difference array.
      • Traverse it and, for each index, find the previous smaller and next smaller elements using stacks(Standard Problem).
      • Multiply the number of choices on the left and right to get the contribution. To avoid counting the same subarray multiple times, use a previous strictly smaller element and a next smaller or equal element.
      • This gives the count of subarrays where the current value is the minimum, which means in those subarrays the difference is greater than or equal to the current element. Hence, these subarrays contribute to all k ≤ current.
      • Finally, apply a suffix sum to get the counts for “k-exquisite subarrays”.
      • »
        »
        »
        »
        3 months ago, hide # ^ |
         
        Vote: I like it +1 Vote: I do not like it

        Yeah I did through the same process. But how did you come up with this logic for avoiding the overcounting, Like I was stuck here only rest I did the same and then I looked at your comment.

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

          I had already solved a similar question involving this idea: question link

          So back then, I think I was mostly just guessing, and then introducing asymmetry worked. I think you can just try guessing it unless you can prove its correctness, or prove it by getting AC.

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Use stack and do it like largest area in histogram on leetcode.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    can you explain how?

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Simply using Monotonic Stack is also O(n).

»
4 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Problems were hard T-T

»
4 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

Posted editorial faster then judging solutions lol!!, unnecessary penalties because of the lag.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

im dead

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

those problems are so good!

»
4 months ago, hide # |
Rev. 2  
Vote: I like it +13 Vote: I do not like it

Tutorials of D and G not understandable.

What is D about, what does it ask for?

What "function" is there in G?

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    D asks for how many numbers from 1 to n such that you can't reach 0 from them using the specified operations in k operations or less

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      Ok, and why does it matter which response Alice receives from Bob?

      If she plays optimally, she would play optimally anyway, independend of the answers. So again, what does this problem asks for?

      What strategy do we want to follow here to find what?

      • »
        »
        »
        »
        4 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        What I said it's what follows from the statement. She doesn't know the number but the infomation she receives is enough to play optimally.

        As I said the problem asks for how many numbers from 1 to n she can't reach 0 in k operations or less...

      • »
        »
        »
        »
        4 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        The response from bob tells her if the given number is odd or even, its just a way to make it seem more complicated or llm proof ig

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

          yes,it is helpful in finding if number is odd or even,

          if number is odd then it is not divisible by any power of 2 except 0,ie 1

          so if x==1 then number is odd else number is even

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    D is asking the amount of numbers that its total digits plus the number of digits equals to "1",are bigger than k, under binary expressions. And it can be solved using the Psacal triangle

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Because Bob gives her enough information to determine the current number is even or odd ,so she will always halve the number if it's even and minus it by 1 if the number is odd.

»
4 months ago, hide # |
Rev. 2  
Vote: I like it +9 Vote: I do not like it

E can be solved with monotonic stack for contribution in O(n) 357602037

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Can you please explain for [5, 1, 4, 2, 3](test case — 1) for k = 2, why the answer is 6.

    1. [5, 1]
    2. [5, 1, 4]
    3. [5, 1, 4, 2]
    4. [5, 1, 4, 2, 3]
    5. [1, 4]
    6. [1, 4, 2]
    7. [1, 4, 2, 3]

    Clearly I can count more than 6. Am I missing something?

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      7th case , 3-2=1

      • »
        »
        »
        »
        4 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        but it is saying any two adjacent elements should differ by atleast k, so 4 — 1 = 3 is satisfying for k = 2.

        • »
          »
          »
          »
          »
          4 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          I think the wording is a bit confusing — I initially had the same confusion as you. What the question means is: "for any two adjacent elements, the difference >= k" i.e. all pairs of adjacent elements differ by at least k.

        • »
          »
          »
          »
          »
          4 months ago, hide # ^ |
          Rev. 2  
          Vote: I like it 0 Vote: I do not like it

          It means if we pick any pair, it should have atleast k difference

          Edit : i.e.,every pair should differ by atleast k

»
4 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Felt like a div 2

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great contest, my first AK on div3 <3.

»
4 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

ive been grinding 1500-1700 in an effort to reach expert and i really thought i was making some progress. i mean, i solved many questions on my own. if not, i was able to atleast get close to the key observations.

and yet i could not solve B and C. even after trying for nearly an hour.

if my math is really this weak, there is no hope of me ever actually getting good at CP, is there? im cursed to never actually improve. all the questions i solved were probably very easy with inflated ratings. or it was just a fluke.

i have had bad contests but this one was the worst. maybe i should just go back to doing LeetCode

EDIT: turns out my mistake for B was that i accidently inverted the if-else conditions and for C i simply missed the case where n == k. i shouldnt have given up so quickly lol. oh well

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    practise makes man perfect. Believe in yourself, consistency is the key.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

    Nah, it's fine... bad contests happen. for me as well, that was the worst contest I've done in months (and I'm doing virtual Div. 3 pretty often ), so... don't let yourself down over just one bad contest :) There is no such thing as "never improving", you just need to compare yourself with yourself from a month ago / year ago for seeing how much you have improved, this here is just a rating that while it should show "how much you improved" it just shows how prepared you were on some specific type of problems ( in this case math ), so yeah, maybe it's just time for both of us to learn some more math tricks on cf, not to give up <3

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    chill, it isn't that deep, just understand the solutions and learn from your mistakes

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Just do CSES? You're probably lacking foundational skill, Codeforces teaches a lot of dumb tricks, it's inefficient to just do a bunch of questions on CF. I'd do something like CSES and USACO Guide if I had to start over, since that's what got me to 1200 in like 4-5 months. You need to categorically learn every technique, not just do a bunch of questions and hope for the best. Grinding CF can help, but it's mostly about learning to discover insights faster, it's very tough to learn all the fundamentals from just CF.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem 2184C — Huge Pile, any way to avoid tle here? ~~~~~ const ll mx = 1e7+123; ll dp[mx]; ll f(ll n, ll k) { if (n == k) return 0; if (n < k) return inf; if (n < mx && dp[n] != -1) return dp[n];

if (n % 2 == 0) {
    ll z1 = f(n / 2, k);
    if (z1 == inf) {
        if (n < mx) return dp[n] = inf;
        else return inf;    
    }
    else {
        if (n < mx) return dp[n] = 1 + z1;
        else return 1 + z1;;    
    }
}

ll z1 = f(n / 2, k);
ll z2 = f(n / 2 + 1, k);
if (z1 == inf && z2 == inf) {
    if (n < mx) return dp[n] = inf;
    else return inf;    
}
if (z1 == inf) {
    if (n < mx) return dp[n] = 1 + z2;
    return 1 + z2;
}
else if (z2 == inf) {
    if (n < mx) return dp[n] = 1 + z1;
    return 1 + z1;
}

if (n < mx) return dp[n] = min(1 + z1, 1 + z2);
return min(1 + z1, 1 + z2);

}

void solve() { ll n, k; cin >> n >> k; // dbg(f(3, 4));

memset(dp, -1, sizeof(dp));

ll res = f(n, k);
if (res >= inf) cout << -1 << endl;
else cout << res << endl;

} ~~~~~

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    n can go till 1e9, you need to think better

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I solved like this, avoided tle:

    // Anshul Gaharwal 007
    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define ll long long
    #define inf INT_MAX
    #define pb emplace_back
    #define ll_inf LLONG_MAX
    
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        int tc;
        cin >> tc;
        while (tc--)
        {
            ll n, k;
            cin >> n >> k;
            queue<pair<ll, ll>> q;
            unordered_set<ll> s;
            q.emplace(n, 0);
            s.insert(n);
            ll res = -1;
            while (!q.empty())
            {
                auto val = q.front();
                if (val.first <= k)
                {
                    if (val.first == k)
                    {
                        res = val.second;
                    }
                    break;
                }
                q.pop();
                if (val.first % 2 == 0)
                {
                    val.first /= 2;
                    if (val.first == k)
                    {
                        res = val.second + 1;
                        break;
                    }
                    else
                    {
                        if (s.find(val.first) == s.end())
                        {
                            q.emplace(val.first, val.second + 1);
                            s.insert(val.first);
                        }
                    }
                }
                else
                {
                    val.first /= 2;
                    if (val.first == k)
                    {
                        res = val.second + 1;
                        break;
                    }
                    else
                    {
                        if (s.find(val.first) == s.end())
                        {
                            q.emplace(val.first, val.second + 1);
                            s.insert(val.first);
                        }
                    }
                    val.first++;
                    if (val.first == k)
                    {
                        res = val.second + 1;
                        break;
                    }
                    else
                    {
                        if (s.find(val.first) == s.end())
                        {
                            q.emplace(val.first, val.second + 1);
                            s.insert(val.first);
                        }
                    }
                }
            }
            cout << res << endl;
        }
    }
    
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Liked B

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Same, I wrote down some simulations and got the answer quite quick.

    I hated A's phrasing though, solved all the way through D before finally understanding what A was asking for (then promptly solving it in one-shot) :<

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

357546787

Did I get a wrong TLE here? I submitted pretty much the same with just making the values very marginally smaller, and I'm pretty sure this shouldn't be close to TLE. (This worked: 357553381)

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    undefined behavior index out of range dp[31][32]

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Ohh, I was confused because it was TLE, and locally it went fine so I didn't check for indexing errors, but since it's undefined behavior anything can happen ig. I see my mistake now, thanks!

»
4 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Problem F and G felt more like an educational round problem. I liked the idea of the query always being 0 or 1.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

using dsu for merging segments in E is a nice trick which I learned, v elegant!

»
4 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

iam i the only one who found B really hard (kinda impossible) i couldn't even understand it it feels bad tbh iam the only one who thinks its problem statement is poorly typed

for example i couldn't solve problem C but at least i get that it is on my skill that i couldn't figure the math idea behind it but for problem B i couldn't even figure out what is it asking me to do !

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

357562263

Problem G's tests can be done with O(NQ) (when it's not supposed to) with proper breaking after cumulative minimum values — wish the testcases there were stronger on that one since the very reason why we implemented the segtree in the first place was to stop Naive simulation

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

I think I got pretty close to D, but I can't figure out where my code's going wrong- I'd be grateful if anyone took a peek at it. 357620086

  • »
    »
    4 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    Idk man

    Edit: Solved it:)

    • »
      »
      »
      4 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      After looking at the code, I managed to locate the issue: it was in my combination logic, namely, the line: res *= (n-k+i)/i. After changing it to res = res * (n-k+i)/i it worked for me as well.

      Thanks for the help :)

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

        Why is that an error, is it coz of some long long -> int, issue?

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

          In the first version, it did the division before doing the final multiplication; it was as if I had written res = res * ( (n-k+i)/i ), which caused the rounding errors to appear. In the second version, the operations are done from left to right, and thus the multiplication happens first, making an exact integer division possible.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I had fun trying to solve A for 2 hours with my limited knowledge

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For some reason i was really convinced that bfs would give tle in C, so i tried to come up with some solution using the bits in n and k.

First, there was a special cases: $$$k=2^d$$$ for some d, and there were a prefix of $$$n$$$, $$$n'$$$, in which $$$n'= 2*2^d -1$$$ then it can be done in $$$log_2(n)-log_2(n')+1$$$ operations, the cost of transforming $$$n$$$ into $$$n'$$$ with floor operations and then making a ceil operation for clearing the ones in $$$n'$$$.

Now, analyzing the binary representation of $$$n$$$ and $$$k$$$, and their prefixes:

If $$$k$$$ is a prefix of $$$n$$$ in their binary representation, then it can be done in $$$log_2(n)-log_2(k)$$$ operations.

Now, if they differ in some bit b in which b is 1 in $$$n$$$ and 0 in $$$k$$$, we would need to turn this bit off in $$$n$$$, which is not possible with our operations while maintaining it in the final result.

But if b is 0 in $$$n$$$ and 1 in $$$k$$$, we can only turn b into a 1 in $$$n$$$ if we "borrow" some less significant bit of $$$n$$$ that is 1, but this borrowing forces all bits that are less significant then b to be 0 (if they can still be present after the borrowing). So for this last case, we need to check if all bit less significant then b in $$$k$$$ are 0. Also, let $$$c$$$ be this number of 0s in $$$k$$$, so $$$n$$$ needs to have a sequence of ones of size $$$k$$$ right after the bit b and also have an additional 1 to be borrowed. If all of these conditions are valid, then it can also be done in $$$log_2(n)-log_2(k)$$$.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For me B > C C is stright forward but B needs some good thinking...

»
4 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

dsu fucker ah

(y is ts wrong)

Spoiler
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My first CF contest able to solve 2 questions (A and C) .

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Just B took me a whole hour... I really liked it though, but my solution wasn't as elegant as the editorial's

ll s,k,m;cin>>s>>k>>m;
ll secs=m%(2*k);
cout<<(secs<k?max({s-secs, s-k, 0ll}):(max(min(s,k)-(secs-k), 0ll)))<<'\n';

Any tips for avoiding min/max stuff and finding the elegant "shortcuts"? I always end up with verbose "unminimized" code.

  • »
    »
    4 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it
    void solve(){
        ll a,b,c;cin>>a>>b>>c;
        ll t = c%b,y=0;
        bool q = (c/b)&1;
        if(q){
            ll o = min(a,b);
            ll z = max(0LL,o-t);
            cout<<z<<endl;
            return;
        }
        else cout<<max(0LL,a-t)<<endl;
    }
    try this 
    
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Dude Contest was actually hard. B was literally tougher than C. C was kinda straightforward could've accepted in one submission but i missed edge case of n==k. I need to practice so much :(

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I need to up solve more. B made me have a stroke. That Div 3 B question was harder than the previous Div 1/Div 2 questions: A, B, C of the Blacksled contest.

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

Unintentionally, skipped the fact that $$$n = 2^x$$$ in problem D and was trying to solve the bonus version the whole time... feels so bad :(

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

    Oh god ahhh same;(

    I even solved it during upsolving and just when I read your comment I noticed oh shit the hell i was doing;)

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Pretty bad contest for me, but I guess it’s a good time to pick up some cool math tricks.

»
4 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

I solved D using a completely different approach. It’s a somewhat unconventional math/pattern-based enumeration solution, ofc not the intended one, but it works and it shows the beauty of Fibonacci sequence.

Dropping my accepted submission here just in case anyone is curious about an alternative way of thinking. Not for learning purposes! For that the editorial approach is far better ig. Submission: 357624461

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For C, I had a different solution based on bitwise.

If we have the desired value K, it will require either 2*K-1, 2*K or 2*K+1 to be formed before K can be formed, as any one of 2*K-1, 2*K, 2*K+1 divides into K. This means we are looking for a way to make N with 2^x * K + A[x-1] * 2^(x-1) + A[x-2] * 2^(x-2) + ... + A[0] * 2^0, where A[i] has value -1, 0 or 1. This is a trope I recall seeing in another problem, just that I can't remember exactly which one it is now.

Now, how do we test for this? We iterate i=0 to 64 until N — (2^i * K) is equal to or smaller than 2^i — 1 (because this is the max we can form as the A[i] * 2^i sum). If N is greater than (2^i * K) — (2^i — 1), since that is now the minimum sum we can achieve with 2^i * K, then K will be formed from N in exactly i operations, otherwise, there is no solution.

Time O(1), memory O(1)

Code:

Spoiler
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

d can be also done using dp

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is $$$nlog^2n$$$ supposed to TLE in G? I solved without using 'walk on segment tree', but my solution got hacked.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Can someone try hacking my code as well please.I believe it should work fine as constraints are 2e5.(why using walk un-necessarily) It is n((logn)^2) only. Here is my 357542232.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I realized the issue, problem wasn't with $$$log^2$$$ factor but I had a high constant term which is why my solution TLEd. On writing a cleaner $$$nlog^2n$$$ solution, it passes in 1 second.

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

    Yes if you use Python. Using C++ is able to pass the tests.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My solution for C is very different

My Code
»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Pretty difficult contest, B was quite annoying.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem F and G felt too standard.(I am not really complaining) But I think particulary G should involve something more tricky(even if educational) than just using one simple observation and bam segment tree.....AC. overall I enjoyed solving problem E the most.Used segment tree for E as well as I couldn't come up with the merging thing.

»
4 months ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

G is cool task

»
4 months ago, hide # |
Rev. 2  
Vote: I like it +5 Vote: I do not like it

For problem D , The number of integers $$$0 \leq m \leq 2^d$$$ such that $$$\text{maxBit}(m) + \text{cntBit}(m) = k$$$ is on A027926 on oeis. Interestingly, the number of unbounded integers $$$m$$$ such that $$$\text{maxBit}(m) + \text{cntBit}(m) = k$$$ is the k'th fibbonacci number.

I only found this because I misread the problem to say alice divides by the largest power of 2 in the prime factorization of n when n is even instead of just dividing by 2. The answer for this different problem comes out to $$$\sum_{i=k+1}^{n} {{d-1}\choose{\lfloor \frac{i}{2} \rfloor}}$$$. When I realized my misread I found the oeis sequence when adapting the solution.

»
4 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

Thanks for fast editorial and beatiful contest. Problem D was amazing! It actually blew my mind.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Also, I think C was much easier than B

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

great problem setting, absolutely loved it!

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i didnt expect to solve only 2 questions in div3 . looking at the edi now the problems seem so interesting

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

G would be C if it wasn't for data structures

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how long does it take for ratings to change since I am new at code forces , I have solved a lot in CodeChef and lc and other platforms bt I dont know about this , if anyone can help it will mean a lot

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D can be solved in $$$O(1)$$$ each query

Code
Solution explanation
»
4 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Since I solved fewer problems in div3 than in div2, f**king!

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D can be solved using digit dp ,first convert the number into its bits form and then use the condition that 2*setbits-1+unsetsbits<=k 357599309 ,you can check my last submission

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B was quite tricky!

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem B.

why for test case

16 7 7 answer is 7? (not 9)

There is only one flip. After flip sand minute s — k = 9. No one does flip anymore.

  • »
    »
    4 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    bcoz in that flip time remaining will be 7 not 9 and leaving time is also 7 so 7 minutes will be left

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Tho I didn't perform well, one of the best div3s I have given so far

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

E can be solved using two maps , one for left and one for right , and then counting contribution for each k , and updating left and right ranges in map . B was tricky .

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This was my First contest, Im happy that I've solved 3 Questions, I hope that Ill improve.

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

another sol for C

Code

link: https://mirror.codeforces.com/contest/2184/submission/357635822

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Solved B in 5 minutes, C in 10 minutes, but didn't solve A in a whole contest lol. The weirdest performance ever

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Ratings are out?

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I am not able to figure out why my solution for D, 357586842 got hacked please help

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Your text to link here... I don't understand why my code failed in Test 2. Could some expert help me find the bug? Thank you.

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B was extremely weird

»
4 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Alternative solution for C:

We can greedily select the next value.

If we can just construct the k with the current n (1 step) we just end the loop.

if n % 2 == 0 it is obvious that we will go to n / 2

if n % 4 == 1 we should go to n / 2 + (n % 2) because it is obviously a better choice than n / 2.

if n % 4 == 3 vice versa

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I saw many submission who used a segment tree in problem E.

Can anyone explain how to do it using a segment tree?

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why is it showing as unrated competition for me?

»
4 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In my sleep deprived mind I thought of just checking for half population one side and another half another side for A, but I was too frustrated with my failed submissions and I gave up in between. Should have tried it.

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

What is "rnk" in solution of problem E

»
3 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

E can be solved without dsu, set or stack. I solved it just using arrays. 357749120 I follow the same strategy as mentioned in the editorial. It can be noted that when we arrive at an index to merge two segments, we only need the left and right segment lengths about that index. So we can maintain a segment_start array and a segment_end array. segment_start[i] = length of segment which starts at i. segment_end[i] = length of segment that ends at i. We can update the arrays as we merge two segments using the lengths. Check my submission for understanding.

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

How does the suggested solution for G (descent approach) has the time complexity of $$$O(n + qlogn)$$$ ? I think, it should still be $$$O(n + qlog^2n)$$$. Because one $$$logn$$$ factor comes from the fact that we are doing binary search and the second $$$logn$$$ factor will be used for checking the sign of the $$$h(d)$$$ function at the points $$$c_l$$$ and $$$c_r$$$ at each point during the binary search.

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

Here's an alternate soln of D, O((logn)^3)

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

int rec(int i,int sum, vector<vector<int>> &dp){
    if(i>0 && sum ==0){
        return 0;
    }
    
    if(i==0){
        return 1;
    }
    if(dp[i][sum]!=-1){
        return dp[i][sum];
    }
    int ans1 =0;
    ans1 = rec(i-1,sum-1,dp);
    
    int ans2 = 0;
    if(sum>=2){
        ans2 = rec(i-1,sum-2,dp);
    }
    
    return dp[i][sum] = ans1 + ans2;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    cin >> T;
    while (T--) {
        
        int n,k;
        cin>>n>>k;
        
        int ans =1;
        
        int final =-1;
        for(int i=1;i<31;i++){
            //fixing this
            if(n&(1<<i)){
                final = i;
                break;
            }
            int sum = k-1;
            
            if(sum > 2*i){
                sum = 2*i;
            }
            
            vector<vector<int>> dp(i+1,vector<int> (sum+1,-1));
            ans += rec(i,sum,dp);
            dp.clear();
        }
        
        if(final+1 <=k){
            ans++;
        }

        if(ans >n){
            cout<<0<<"\n";
        }
        else{
            cout<<n-ans<<"\n";   
        }
        
    }
    return 0;
}
//
»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hey everyone ! can anyone please say where to practice problems for improving my problem solving efficiency in contests . and practicing methods which u felt good .currently my rating is 1000 .i wish to improve it kindly help me out .

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

    Hey, a sophomore here!

    I have been relatively active in the platform for multiple months and I believe this might help you out.

    1. Problems to practice can be found across multiple websites. I recommend you to try Hackerrank, CSES problem set(highly recommended) and leetcode(standard across Indian engineering institutes to practice for placements and a lot more).

    2. Problem efficiency doesn't arise from sheer talent or the number of problems you have solved in the past for your future. It's the underlying maths which you're able to apply on that carries you forward.

    1. Also, this is about rating: Ratings are not marks in the first place. Just a signal about how good or progressive the user is in the platform. Most yearn for ratings, and the process to improve it spans from multiple weeks to possibly, multiple months. Consistent efforts and the ability to apply maths compound gradually unless you don't learn the concepts involved in a problem properly.

    Here's an extra suggestion for you: Write formal math proofs for problems you come across especially for datastructures.

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

it was tuff asf..could not solve B..also got A wrong coz of panic and language problem...i think framing of question language is better in div 2

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

I felt that the previous Div 2 a,b questions were much easier than this Div 3 contest.

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

The author's solution to G by method of descending is really elegant.

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

For me it was great contest and first oroblem is soososooooooooooo easy

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

I checked EFG and it's not very difficult. Is ABCD more difficult than EFG?

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

can someone provide the ratings of each ques

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

my approach for problem c

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

int solve(int n, int k, int t) {
    if (n < k) return -1;      
    // if(n==k)return t;
    int a = n / 2;
    int b = n - a;
    if(k==a || k==b)return t+1;
    int num = a;
    if(a!=b){
        num = a%2==0?b:a;
    }
    int ans = solve(num, k, t + 1);
    return ans;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        if(n==k){
            cout<<0<<endl;
            continue;
        }
        int ans = solve(n, k, 0);
        cout << ans << endl;
    }
}

whenever i decompose a number i check if decomposed number is my target,and if not among the decomposed number i take the odd number because on decomposition of these i will get all the possible factor and can ignore the other number please take a example you will understand,although i am sillly mistake person i was not able to solve them in contest,for one hour i was struggling to find the mistake i made,i found the mistake in b but was not able to find in problem c

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

can someone please tell we why this approach is wrong for C problem. ~~~~~ 358167776

~~~~~

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

For problem F, the problem statement says:

"You choose any vertex of the tree v (including the root or a leaf) and "shake" it. After that, cherries fall from all the leaves that are descendants‡ of vertex v (if vertex v itself is a leaf, then a cherry falls from it). If cherries have already fallen from any leaf before, the tree will break, so such a situation must be avoided."

And it identifies "Descendants of vertex v" as follow:

"‡The descendants of vertex v are all vertices u≠v such that on the shortest path from the root to u, vertex v is encountered."

Which I guess it is obvious enough (at-least for me & that I'm not missing anything) that if I for example choose any node to shake: then I can't shake it again or any other node below it. Why? because from my understanding if I shake a node then all cherries in its children will fall, if I then shake it again or any other node below it, it will also affect the leaves and the rule "If cherries have already fallen from any leaf before, the tree will break, so such a situation must be avoided." would apply. However in the editorial of the analytical solution for F, it claims that I should initially shake the root node, then I can shake anything I want as long as it's not a leaf, how so? Shouldn't the rule still apply?

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

    INDEED, THOUGH AS A WISE MAN ONCE SAID...YOU DO NOT GET EVERYTHING YOU WAN IN LIFE, THAOU BE LIMIT THE EXCEPTIONAL TO CONTROL THE INEVITABLE

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

in problem G, how does the segment tree descent work, can someone explain

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

I would like to clarify regarding the similarity flag on my submission.

I solved the problem independently during the contest. My approach was based on modeling the tree using a DFS and maintaining a bitmask representing possible values modulo 3 from each subtree. For each child, I merged masks by combining possible residues and updating the current node’s mask. Leaf nodes returned the base mask, and finally I checked whether residue 0 was achievable at the root.

I did not share my code, discuss implementation during the contest, or use any public code-hosting or collaborative platform. The similarity may be because this problem leads to a very standard tree-DP-with-bitmask approach, where transition logic and structure naturally become similar across solutions.

I respect Codeforces rules and am willing to provide any clarification if needed.

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

Another approach for problem F.

Spoiler
»
3 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How do you solve the bonus for D..

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

E was such a beautiful Problem..

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

In problem c according to the given solution, if we give next iteration just a odd number then also it will work.

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

i got goomba stomped in virtual ;-;

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

Problem E is really nice! I first tried using a difference array plus a monotonic queue to track the minimum difference, but it bombed — O(n²) time complexity, got TLE on test case 7 straight up. So I switched things up: still stuck with the difference array, but swapped the monotonic queue for a monotonic stack to keep track of the maximum valid interval length. After that, the inclusion-exclusion principle made it a piece of cake, and it’s O(n) time overall. Here’s my submission if anyone wants to check it out: 363405796