Little_Sheep_Yawn's blog

By Little_Sheep_Yawn, 7 months ago, In English

2153A - Circle of Apple Trees

Hint 1
Hint 2
Solution
Code (C++, maomao90)
Code (Pypy3.10, Little_Sheep_Yawn)

2153B - Bitwise Reversion

Hint
Solution
Code (C++, maomao90)
Code (Pypy3.10, Little_Sheep_Yawn, using the bonus)
Bonus

2153C - Symmetrical Polygons

Hint 1
Hint 2
Solution
Code (C++, maomao90)
Code (Pypy3.10, Little_Sheep_Yawn)

2153D - Not Alone

Hint 1
Hint 2
Solution
Code (C++, maomao90)
Code (Pypy3.10, Little_Sheep_Yawn)

2153E - Zero Trailing Factorial

Hint 1
Hint 2
Hint 3
Solution
Code (C++, maomao90)
Code (Pypy3.10, Little_Sheep_Yawn)

2153F - Odd Queries on Odd Array

Hint 1
Hint 2
Solution
Code (Pypy 3.10, Little_Sheep_Yawn)
Code (C++, maomao90, slightly different)
  • Vote: I like it
  • +117
  • Vote: I do not like it

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

Auto comment: topic has been updated by Little_Sheep_Yawn (previous revision, new revision, compare).

»
7 months ago, hide # |
 
Vote: I like it +33 Vote: I do not like it

this contest made me nut.

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

Auto comment: topic has been updated by maomao90 (previous revision, new revision, compare).

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

Lightning quick editorial!!!

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

tutorial is broken

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

Nice contest and fast editorial! But surprisingly hard C :(

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

What a fast editorial !!

»
7 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

For problem B,we can calculate the sum of each bit of x, y, z. If the sum of a bit is 2, it is NO, otherwise it is YES

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it -6 Vote: I do not like it

    If x^y^z == x|y|z it is Yes. Otherwise it is No.

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

      man explain :V:VVV:VV:V I need you wisdom, how did you get to that?

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

        I'm wondering why it is heavily downvoted :DDD

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

          Because people automatically assumed that you used ai. Happened with me, I also posted a different approach to problem D, used ai to articulate the solution's explanation since i am not a native English speaker, but they heavily down voted the solution.

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

            I don't think AI will give this answer. Maybe they don't understand. Anyway don't care about them. It's not important at all. So do your best.

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

              Thanks for the encouraging words, but it is just strange to get downvoted on an approach you found out of your own :(

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

      how did you think of it in the first place

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

        Well, the funnier thing is that actually I guessed it, that sum of a bit shouldn't be 2, and I haven't proved it yet.

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

          I had a bit of a diffrent aproach. Out of the starting equation i made some other. Then i set a=x|z, b=x|y, c=y|z. After that i just checked the starting conditiones and the other equations.

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

      why this solution works , can u please explain it

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

        Because, if and only if there is a bit that is equals 1 in exactly two of the numbers , then this condition isn't true because: 1 ^ 1 ^ 0 = 0 but 1 | 1 | 0 = 1

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

    How did you come up with this logic ?

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

      create a table for bits of a,b,c and resultant bits of a&b,b&c and c&a and you will see that in all the 8 cases sum of bits of a&b,b&c and c&a is never 2, it can only be 0,1,3

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +8 Vote: I do not like it

    if x&y == y&z == z&x it is yes else no

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

    my idea is calculate x & y (= a & b & b & c = a & b & c), y & z ( = b & c & a & c = a & b & c) and x & z ( = a & b & a & c = a & b & c) ,if all the three result are consistent , the answer is YES

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

    why this soultion works , can u explain?

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

Fast Editorial !

Nice problem Set ! But C was hard

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

I thought D could be solved with binary search by searching for a delta to add to the number, so ai keeps in the range [ai-delta, ai+delta], and with that I tried to delimit the blocks but couldn't find a way TT

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

can anyone please tell me what am I doing wrong here? 343006641

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

Auto comment: topic has been updated by maomao90 (previous revision, new revision, compare).

»
7 months ago, hide # |
 
Vote: I like it -23 Vote: I do not like it

omg E WAS SO GOOD!!!

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

I've thought $$$O(T\cdot\operatorname{PrimeGap}(n)^2\log^2n)$$$ won't pass E and wasted 1hr+ trying to improve my solution to $$$O(T\cdot\operatorname{PrimeGap}(n)^2\log n)$$$...

The problem itself is excellent but the constraint is so tricky :/

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

Hmm, managed to find another solution to b, which is also a quick trick, as in the "bonus section": just check whether (x & y) == (y & z) && (x & y) == (x & z). The solution has passed all tests :)

For those, wondering why, my logic was that a & b & c is equal to x & y (because a & b & b & c = a & b & c) and similarly to x & z and y & z, so all these expressions must be equal to each other.

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

wow, people were able to solve B surprisingly fast

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

Solved F with exactly same solution but without any thinking about tree. Just got that idea randomly :)

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

thanks for superfast editorial

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

C made me lose hope

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

C was out of my league!!:)

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

I have a shorter solution for B.

I just print YES if X&Y == Y&Z == X&Z and NO otherwise. Proof : (1) It exists a and b as a & b = X (2) It exists a and b as b & c = Y So (1) AND (2) <-> a & b & b & c = a & b & c = X & Y.

So if we can find a,b,c we have X&Y == Y&Z == X&Z == a & b & c.

Sorry for my poor english and thx for this very good contest !

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

    **I didn't participate (I was sleeping half the time), but I solved the question after contest. I saw others' solution later which were x&y == y&z == x&z but I couldn't understand it. Thanks for the explanation.

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

    I can't understand. Can u explain more?

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

Here's a similar problem to today's B but harder: instead of construct from and to or, this problem do from or to and: https://mirror.codeforces.com/contest/1903/problem/B

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

this comment is no longer relevant.

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

    Sir I think if he ai cheat his rank would be lot higher. also i think simulating over bits would've been a legit strat considering anybody who cared about speed could've thought of brute force. u should not accuse him of cheating becuz he's indian

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

      We both Gave contest together yesterday, we spend almost an hour to that question but didn't get it.

      we tried our best and build logic on that particular solution, but gives wrong answer. So, we use AI to update our changes

      Should it be a cheating or help from AI.

      At final. we use AI but I didn't submit the solution bcz we didn't understand.

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

C was interesting even if I couldn't solve it..

I tried an approach similar to the editorial but idk why it fails. my submission

I tried pairing all possible ones and for the single sticks i just took the longest 2. I couldn't figure out a counter case to this

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

    Try 5 5 7 24, you can’t take 24 because it’s too long

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

      That is why I added the polygon inequality check. Any reason why it is still wrong? My submission :342989726

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

        Think there’s some issues with your casework, keep in mind that 1: you may not take two bad segments (maybe 1 or 0) even when more bad segments exist; and 2: the bad segment(s) you take may not be the biggest bad segments available.

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

        As an example, I think your code returns 0 on both these cases:

        • 5 5 7 24 —> 17

        • 5 5 7 8 24 —> 25

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

          Ahh, I see what you are saying, I needed to give polygon inequality preference and do casework with it. Thanks!

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

      I understand the case where a single stick can be added but I am still confused why we need to choose 2 sticks where |long — short| < curPerimeter.

      I am having a hard time visualizing this case (where 2 sticks can be added).

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

        Take the case 5 5 7 8 24: curPerimeter is 5+5 = 10 and there are 3 extra sticks, but you can't choose 24 and 8 because 5 + 5 < 24 — 8. From a geometrical view this means that 5 5 8 can't reach both ends of 24, so we can't actually make a polygon with 5 5 8 24.

        Solution is to take 5 5 7 8, you can form a trapezoid with these segments.

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

          ohhh I get it now!

          So for the case 5 5 1e9 1e9 + 1: we can take all of them since the single sticks 1e9 and 1e9+1 have a difference less that curPer (5 + 5) so we can place these 2 sticks on opposite sides

          And for the case 5 5 1e9 1e9 + 10: the answer would be 0 since we can only take 5 & 5 but it would form a polygon.

          Thank you so much for the help!

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

          I am also trying the same approach as the editorial for problem C. Can you please point out what am I doing wrong? 343596059

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

Alternate brainless solution for F using a persistent segment tree bash:

Definitions:

  • $$$l(x)$$$ — first occurrence of $$$x$$$
  • $$$r(x)$$$ — last occurrence of $$$x$$$
  • $$$p(i)$$$ — $$$j$$$ where $$$a_i$$$ is the $$$j$$$-th occurrence of $$$a_i$$$

Notice that an array is cute iff the set of segments $$$[l(x), r(x)]$$$ forms a laminar family (no two segments partially intersect).

When answering some query $$$[L, R]$$$, then there will be four kinds of elements $$$x$$$:

  1. $$$l(x) \lt L \leq R \lt r(x)$$$, and there's at least one occurrence of $$$x$$$ within $$$[L, R]$$$: We can prove that there will be at most one such $$$x$$$. How do we find it? Build an rmq structure over an array of $$$r(a_i)$$$, query the maximum value of $$$r(i)$$$ on $$$[L, R]$$$. Then, simply check if the corresponding $$$x$$$ has an odd number of occurrences on our query interval, and add the contribution to the answer.
  2. $$$L \leq l(x) \leq r(x) \leq R$$$: for these segments, notice that we already know the number of elements $$$x$$$ that will lie within our range, so we pre-build a merge-sort tree to handle them (I assume this is simple enough to not deserve more explanation).
  3. $$$l(x) \lt L \leq r(x) \leq R$$$: to handle these, we pre-build the following data structure:
    • For every $$$x$$$, we build a set of ranges $$$S_x$$$. For every pair $$$i, j $$$ that satisfies:
      1. $$$a_i = a_j = x$$$
      2. there lies no occurrence of $$$x$$$ in $$$[i + 1, j - 1]$$$
      3. there are an even number of occurrences of $$$x$$$ on $$$(j, n]$$$
      , we add $$$(i, j]$$$ to $$$S_x$$$.
    • We start with a blank persistent segment tree of size $$$n$$$, and go over $$$i$$$ from right to left. When at $$$i$$$, there's at most one value of $$$x$$$ that satisfies $$$r(x) = i$$$. For all segments $$$(l, r]$$$ in $$$S_x$$$, add $$$x$$$ on the segment tree.
    • When answering query $$$[L, R]$$$, the contribution of these type-3 segments will simply be (value at position $$$l$$$ in our persistent segment tree when we reached $$$i = l$$$) — (value at position $$$l$$$ in our persistent segment tree when we reached $$$i = r + 1$$$).
  4. $$$L \leq L(x) \leq R \lt r(x)$$$: this is symmetrical to the previous case, and can be handled analogously.

This works in $$$O((n + q) \cdot (\log {q} + \log^2{n})$$$ time.

Code: 343034475

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

unordered_map made me win the battle but lose the war for C.

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

Answering the bonus question for B. There are a few things to note: 1) It is necessary for a to be such that a&(x|z)=(x|z). (Basically, a is a supermask of x|z) Detail: if that is not the case, then at the position where x|z is 1 but a is 0, it will give both x and z to have 0 (because of & with a), which will contradict z|x having 1(both should not be zero at that position). A similar statement could be made for b and c.

2) Suppose a is such a supermask and similar for b and c, such that all the conditions are satisfied. Then, any submask of a will also satisfy it, provided it is a valid supermask of x|z. Detail: Suppose some position where a is set to 1, and setting it to 0 will still make a supermask of x|z. Since it is a supermask of x|z (and not equal to it otherwise, setting to 0 would not be a valid supermask), it means b and c have a 0 at that position. Changing it to 0 will not alter the constraints. A similar statement could be made for b and c.

From these observations, we can choose the minimum supermasks a, b, c, i.e., (a, b, c) = (x|z, y|x, z|y) and verify. If this does not satisfy, then no other solution could satisfy.

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

Thank you for the lightning-fast editorial! The hints and solutions are clear and well-structured, making it easy to follow along after the contest. Problem B stands out as a thoughtful challenge on bitwise operations, emphasising reversal and bit manipulation in a clever way. This might help make it more accessible for newer participants. Overall, a solid problem set with great variety—kudos to the authors!

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

CLICK ON THIS IMAGE Whats the explanation for this, why people with better ranks and less rating got minus while this guy SubArU_76 got positive delta.

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

Can anyone help me what's wrong in code for problem C 343001567

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

For problem B, I found out that if this condition is met, then there exists a, b, c that meets the requirements: (y & z) == (z & x) == (z & x).

so this is my code and it passed the tests:

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

int t; int x; int y; int z;

int main() {
    cin >> t;
    while (t--) {
        cin >> x >> y >> z;
        
        if ((y & z) == (y & x) and (y & x) == (x & z) and (x & z) == (y & z))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}

Submission: 342983760

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

(task E) Hope this helps some reader to understand that this one proof is made by contradiction.

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

Another bonus for 2153B - Bitwise Reversion: Checking the value of

(x | y | z) == (x ^ y ^ z)

.

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

Why give the F such a big timelimit

»
7 months ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

This round is something nice that I can solve both E and F on my own, which I really like it.

As my approaches are different from the editoral, I'll take them down.

E
F, I didn't use the cute property!
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B one line solution : if (((x | y | z) ^ (x & y & z)) & ((x & y) | (y & z) | (z & x))){no} else yes

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

this is my solution for B and I'm very satisfied with it :)

#include <bits/stdc++.h>
using namespace std;
bool check(int x, int y, int z) {
    do if((x & 1) + (y & 1) + (z & 1) == 2) return 0; while(x >>= 1, y >>= 1, z >>= 1, x + y + z);
    return 1;
}
signed main() {
    int t, x, y, z; cin >> t;
    for(int i = 1 ; i <= t && cin >> x >> y >> z ; i++) cout << (check(x, y, z) ? "Yes\n" : "No\n");
    return 0;
}
»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone please check my submission for problem C and let me know why my code is failing in test case 2

https://mirror.codeforces.com/contest/2153/submission/343057370

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

    If you decide to select two numbers from the remaining ones, one of them does not necessarily have to be the best choice when selecting only one. If you are still confused, look at the following set of Hack:

    input:
    1 
    5
    5 5 3 11 12
    correct answer:
    33
    your answer:
    25
    
    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Yay I get that that's why I tried correcting that and this time I tried running two seperate for loops first time to get a single nonsymmetric edge and the second loop to try and get two nonsymmetric edge and get the best out of two . Still I couldn't get an AC.

      https://mirror.codeforces.com/contest/2153/submission/343058487

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

        Wrong 1:

        in line 49:

        if(perimeter>nonsymmetrical[i] && perimeter+nonsymmetrical[i]>nonsymmetrical[i+1])

        why check perimeter>nonsymmetrical[i] ?

        Wrong 2:

        If you only find one pair of edges, there must be at least one other edge; otherwise, it is impossible to form a polygon.

        Hack:

        input:
        1
        4
        5 5 20 100
        correct answer:
        0
        your answer:
        10
        

        Obviously, you cannot just choose "5 5".

        After making these two changes, it will be accepted.

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

There is very easy and intuitive solution for B

    a = x | z;
    b = x | y;
    c = y | z;

    if(((a&b) == x) && ((b&c) == y) && ((a&c) == z)){
        cout<<"YES"<<endl;
    } else {
        cout<<"NO"<<endl;
    }

I think its pretty self explanatory

also problem D was very nice :)

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

Problem C editorial

length of the long odd stick and even odd stick is less than the total length, it should be short odd stick instead even odd stick?

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

So, no one is gonna talk about C being harrrrd

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

For problem B , we can notice x=a&b, y=b&c, z=c&a,

if we take x&y=a&b&b&c=a&b&c, same for y&z and z&x we got a&b&c , this means (x&y)=(y&z)=(z&x), just checking this got accepted

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

Little_Sheep_Yawn and maomao90, thank you for this great contest.

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

I want to bonus you guys another approach way for problem B

I think the editorial code is too long and my way only this 342949235 Explain:

If we read the problem carefully, we easily notice that never get 2 values out of 3 (a&b, b&c, a&c) = 1

So we only have:

  • 0 bit = 1

  • 3 bit = 1

If at a bit there are exactly 2 bits in (bx, by, bz) equal to 1, a,b,c is not satisfied

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

C was too brainstorming for me, too much edge cases to find! But, really enjoyed it.

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

Can someone check my 342993457 of question C, cf is always wa 2, but the example is too large, and the hack examples in the comment section that I tried were all correct.

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

    ok, I solved it because the lowerbound exceeded the int range.

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

      what is the actual logic? my thinking is that first we will add all sticks with even or nearest small even. then we can add 2 sticks with max length which had odd frequency. and checking diferently for n==3.plz see this 343110589

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

        An even number of edges must be selectable.

        Define the sum of the even-numbered edges as res, and then discuss three cases:

        first, where the axis of symmetry is at the intersection point, meaning all edges are even, in which case it is necessary to ensure there are at least two even edges;

        second, where the axis passes through one edge, which can then be odd, but it must be strictly less than res;

        finally, where the axis passes through two edges. My approach is to enumerate the shorter edge x and then find the longest edge that is strictly less than x + res.

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

How to even think around problem D, are there any problems applying similiar ideas?

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

    Yeah quite many. It's just basic dp. Remember what is dp, its dividing a problem to subproblem to eventually solve it. Similiraly here, when you think about long equal segment, you can think it as segments of 2 or 3 length. So you are just thinking about cost of making equal 3 or 2 consecutive elements and cost to make equal behind this segment (I'm talking about dp[i-2] and dp[i-3]). Something like that

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

      no I don't get what is basic in this question, I tried a dp with 2 states. Something like state 1 if it is to be made equal to the element to the left of it and state 2 to the right of it. I got wa2. I don't understand how the 2 and 3 block solution is correct, would be grateful if you can give me the proof.

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

Problem C

Why my code is giving TLE with unoredred_map and Accepted with map ~~~~~ //this is code

include <bits/stdc++.h>

using namespace std;

define int long long

signed main() { // your code goes here ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin>>t; while(t--) { int n; cin>>n; int a[n]; unordered_map<int,int>m; vectorv; int ev=0; for(int i=0;i<n;i++) { cin>>a[i]; m[a[i]]++; }

    int ans=0;
    for(auto u:m)
    {
        if((u.second)%2==0)
        {
        ans+=u.second*u.first;
        ev+=u.second;
        }
        else
        {
        ans+=(u.second-1)*u.first;
        ev+=u.second-1;
        v.push_back(u.first);
        }
    }

    sort(v.begin(),v.end(),greater<int>());
    int x=v.size();
    int k=0;
   int ans1=ans;
    if(ans>0)
    {
        for(int i=0;i<x-1;i++)
        {
            if((ans+v[i+1])>v[i])
            {
                k=v[i]+v[i+1];
                break;
            }
        }

       for(int i=0;i<x;i++)
       {
           if(v[i]<ans)
           k=max(k,v[i]);
       }

    ans=ans+k;

    }
    if(ans1==ans && ev<3)
    cout<<"0\n";
    else
    cout<<ans<<"\n";




}

}

~~~~~

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

    unordered_map is hashing and its worst case search complexity is O(n) where as map is avl or binary tree(balanced) thus its worst case search complexity is O(lgn)

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

      thnx

      So there is a risk in using unordered_map,so one should always use map isn't?

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

        honestly at my current level the answer I can give is yes use map and set instead of unordered versions. I am not sure if for more difficult questions this would work or not

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

Problem D is very coooool, bro

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

    How to think of this approach, I mean I got the intuition of using DP. But how to think of this 2 block and 3 block approach Is there any other approach possible and is there any other similar question

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

      Something that helps me find the approach . just reading the question carefully and trying to find constants factor and greedy sub-parts.

      Greedy part :

      Here some element always has to be paired with something else (2 — block ) nearby

      if the other something is the only pair of something previous , then you need pair all 3 ( 3 — block ). ( because if you pair these 2 , then the third might be left without a pair)

      I messed up coding this during the contest tho , but my approach was mostly correct

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

https://mirror.codeforces.com/contest/2153/submission/343125042 Can anyone tell my why my code for C is giving wrong ans.

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

Can someone please prove why my solution to B works, I found out that this condition is necessary and just submitted it to see if it works. I can not prove how is it sufficient. Thanks

343127275

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

In problem C, how do we check a polygon for degeneracy?

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

Problem B:

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

void solve() {
    int x, y, z;
    cin >> x >> y >> z;

    int a = x & z;
    int b = x & y;
    int c = y & z;

    if (a == b && a == c && b == c)
        cout << "YES\n";
    else
        cout << "NO\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--)
        solve();
}

Why was it accepted?

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

    coz your vars are all x&z and x&y and y&z, which are all equal only if the condition specified in the question met, coz x&z from the question or any of the others will always equal something like this a &b & b & c or a & a & b & c and so, which is a & b & c, so if all of the three have the same value then a & b & c exists, and if so, then a and b and c exist

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

      Can you please explain with an example.

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

        Question says

        a&b=x b&c=y a&c=z

        and this mean

        x & y = (a&b) & (b&c) = a & b & c

        x & z = (a & b) & (a & c) = a & b & c

        y & z = (b & c) & (a & c) = a & b & c

        so the question conditions meaning that there must be some value (a & b & c) let's call it k, such that x&y = x & z = y & z = k

        so if all of the three (x&y, x&z, y&z) are equal then this value k exists, and if so, then there must be a and b and c that make this value k, that's it

        Example

        x=3 y=4 z=6

        x & y = 0

        x & z = 2

        y & z = 4

        then as the three are not the same so the conditions of the questions will fail and this means there is no value k which means there are no values a, b and c

        Summary:

        a&b=x b&c=y a&c=z

        means x&y=x&z=y&z=a&b&c, so try to check if they are the same as this will guarantee the existence of a&b&c which will guarantee the existence of a, b and c

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

Bro why C is so hard

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

2153B — BITWISE REVERSION IF ((x&y) == (y&z) && (y&z)==(z&x)) THEN YES ELSE NO

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

My sol for B was I noticed that x & y = a & b & c same for x & z and y & z (from given eqs)

so I said if x&y == x&z == y&z then YES else NO, I thought everyone thought like that :)

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

Sol for C

342957538

I think it's easier to read than editorial's

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

343061880 why this submission is giving wrong answer on test case 4 please if someone can help debugging me ?

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

In Problem B , we can just check: ((x&y) == (y&z) && (x&y) == (z&x)) ? "YES" :"NO"

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

I still did not get the intuition for this D question(Not alone). I mean how exactly to come across this approach and are there any similar questions I can do

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

Why the code(pypy3.10) for F will RuntimeError on 1?

I haven't learned pypy,I just want to know how long it need.

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

How do we check non-degeneracy in the С problem, that is, each side is less than the sum of the others

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

Why the heck is the code for C THAT green!?

It hurts the eye.

Also I think there was a typo here: "length of the long odd stick and even odd stick"

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

Regarding the sentence in question 1, I believe there is ambiguity. "Note that you are allowed to skip an apple when you first encounter it, and you can choose to eat it later on a subsequent cycle." This sentence implies that you can only skip an apple once. For example, [5,4,3,1,2], the correct answer is 5. However, if we interpret it as meaning that each apple can only be skipped once (and must be eaten the second time it is encountered), then the answer is 4, because you cannot skip 5 to eat 4 again.

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

Hello, I received a message about a coincidence for Problem 2153B, submission [342960539]. I want to clarify that I wrote the entire code myself during the contest. Unfortunately, two of my friends (sim_ple and Nurmuhammet) asked to see my code during the contest, and I showed it to them, believing they only wanted to understand the approach. Without my permission, they then submitted the same code. I sincerely regret this mistake — I did not realize that even showing my code could be considered a violation, and I will never do this again. Please note that I submitted before they did, and I am the original author. I fully accept responsibility for my part and kindly ask for your understanding.

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

this problem was quite hard as a beginner

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

There is a simpler solution to problem B using bitwise OR 343340600

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

10s TL is too generous 343615964

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

Little_Sheep_Yawn Problem F tutorial, "For subtrees that are a single vertex, they have the same value as the LCA", this statement seems to be contradictory to the construction of the tree ?

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

Why is the minimum value obtained in Problem E not the case when $$$v_k(a!) = v_k(b!)$$$?

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

Has anyone passed F with a time complexity of $$$O(n \times sqrt (n))$$$. I think this complex solution can pass this question, but in fact, I received Time limit exceeded on test 6

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

F could be easily solved using SQRT Decomposition

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

Why is it true in div2C:

"As long as the difference in the length of the long odd stick and even odd stick is less than the total length of the pairs of sticks with identical length, we can use the long odd stick and short odd stick."

Is it because if we denote longer base side length as a, shorter as b, the half of the total length of sides forming pairs should be larger than difference a/2-b/2 (strictly exceed in order not to be degenerate), as segment length, connecting a and b, should be greater than 0 (sort of triangle inequality)?

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

In D solution, I think we won't need 4 cycles, 3 would be sufficient.

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

for B, x = a&b, y = b&c, z = a&c , so x&y = a&b&c, x&z = a&b&c, y&z = a&b&c, Just make them equal. Here is my implementation:363764271