Error_Yuan's blog

By Error_Yuan, 4 months ago, In English

1869A - Make It Zero

Author: Error_Yuan

Hint 1
Hint 2
Solution
Implementation
Rate the problem

1869B - 2D Traveling

Author: programpiggy

Hint
Solution
Implementation
Rate the problem

1868A - Fill in the Matrix

Author: Error_Yuan

Hint 1
Hint 2
Solution
Implementation
Rate the problem

1868B1 - Candy Party (Easy Version)

Author: Error_Yuan

Hint 1
Hint 2
Hint 3
Solution
Implementation
Rate the problem

1868B2 - Candy Party (Hard Version)

Author: Error_Yuan
Please, read the tutorial for B1 first.

Hint 4
Hint 5
Hint 6
Solution
Implementation
Rate the problem

1868C - Travel Plan

Author: programpiggy

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution

$$$\mathcal O(\sum(m\log n+\log^3n))$$$ solution by programpiggy:

Implementation

$$$\mathcal O(\sum \log^3n)$$$ solution by sszcdjr:

Implementation

$$$\mathcal O(\sum \log^2n)$$$ solution by sszcdjr:

Implementation

$$$\mathcal O(\sum m\log n)$$$ solution by bilibilitdasc:

Implementation
Rate the problem

1868D - Flower-like Pseudotree

Author: sszcdjr

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Implementation
Rate the problem

1868E - Min-Sum-Max

Author: duck_pear
Huge thanks to Kubic for the development of this problem!

Hint 1
Hint 2
Hint 3
Hint 4
Fun Fact
Solution
Implementation (by Artyom123)
Rate the problem

1868F - LIS?

Author: Error_Yuan

Hint 1
Hint 2
Hint 3
Solution
Implementation
Bonus
Hint for Bonus

Bonus solution by duck_pear:

Implementation
Rate the problem
  • Vote: I like it
  • +14
  • Vote: I do not like it

»
3 weeks ago, # |
  Vote: I like it -50 Vote: I do not like it

First Comment!!!

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

thanks for fast tutorial

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

wtf!! 4 months ago?

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

Enjoyed the contest thanks for the fast tutorial.

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

anyone knows edge case of test case 3 of problem b?? my sumbission :- https://codeforces.com/contest/1869/submission/222740219

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

    Instead of m1=INT_MAX, assign it with a bigger value like LLOMG_MAX>>2.

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

    use 1e18 instead of INT_MAX

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

    I made the same mistake as you can see in my submissions. Actually the distance can be bigger than MAX_INT so you need to compare with a bigger value like 1e18.

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

    because you declared it as a int(integer)

    the max size of int is ~2000000000(1e9*2)

    but the max answer is when become the distance between 'A' and "Nearest major city" is 4*1e9 (major city is x=-1e9 ,y=-1e9 ) and ("A" is x=1e9 , y= 1e9 )

    So abs(Xmajor-Xa)+abs(Ymajor — Ya)=4*1e9

    and the same thing to distance between the nearest major city And "B" is 4*1e9 So the max answer is 4*1e9 + 4*1e9= 8*1e9 the max value u can store in Integer is 2*1e9 so u need Long Long .

    i hope the explain is clear sorry for bad english :D

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

    thnx a lot guys

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

ORZ fast tutorial

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

Typo in B1, should be $$$\implies a_i<a_j$$$

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

Why I am getting pretest failed in Problem A ? Here is the code

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

    In problem Make It Zero

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

    try the case

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

    when you do the last one, you are just replacing $$$a_{n}$$$ with $$$a_{n}$$$.

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

      I am replacing a[n] with XOR of a[n] and a[n] which is 0 as p and r can be equal(given in the question's constraint)

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

        l and r . Sorry for the typo

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

          You are replacing a[n] with a[n]. When you do the xor for only one number, you don't get the xor of 2 numbers. To make it more clear, assume the operation was multiplication in stead of xor. When you want to find the product of the numbers from l to r, where l = r = n, your answer is a[n], not a[n] * a[n]. I hope this approach helped you visualise your mistake.

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

        The problem said you replace each $$$a_i$$$ with $$$a_l\oplus a_{l+1}\oplus\cdots\oplus a_r$$$, for $$$l\le i\le r$$$.

        So for example,

        • if $$$l=1$$$ and $$$r=3$$$, you set each $$$a_i=a_1\oplus a_2\oplus a_3$$$.

        • if $$$l=1$$$ and $$$r=2$$$, you set each $$$a_i=a_1\oplus a_2$$$.

        • if $$$l=1$$$ and $$$r=1$$$, you set each $$$a_i=a_1$$$.

        Do you see it now?

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

          Yesh got it now...btw awesome explanation

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

Thanks For the Lightning Fast Editorial

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

Here is my solution using dijkstra's if anyone wants to have a look. Please check it here Great solution in the tutorial by the way, will get there one day.

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

Quick question, in 2D Traveling how are we making sure that there are 2 major cities in between source and destination?

edit — got it, it doesn't matter!!

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

    In the shortest path, there are either 2 major cities between source and destination, or none.

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

    Well we don't have to verify that there are 2 cities.

    Think of it like this, both cities A and B have a closest major city, except if k=0 in which case the answer is just the direct flight from A to B.

    Using the fact that both A and B have a closest major city, we can calculate for both A and B which major city is closest to them, just by iterating over all major cities and calculating the distance and keeping track of the shortest distance.

    Now we know that we can go from any major city to any other major city for 0 cost, and even if both A and B are closest to the same city, our solution still works.

    Then we can simply say ans=min(AtoMAJOR+BtoMAJOR, AtoB).

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

How to aproach MEX problems? i rarely got solve them

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    1. Practice more problems ...

    2.(Might be silly tip):Use Pen and Paper while you do rough work especially for math ones.

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

got wa in b just because of taking max value for mins = 1e9

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

is there any alternative solution for div2 D1? i tried this — https://codeforces.com/contest/1869/submission/222801815

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

Any simpler explanation for B2? I can't quite comprehend the way mentioned in the editorial lol

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

In D1B, I wonder how many people proved (before submitting) that we can always choose a starting point, or at least noticed that it needed a non-trivial work to prove... I think this part is the hardest part of the problem so I feel like it is "the more you think, the more you lose points" problem.

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it -12 Vote: I do not like it

    Yep, the conclusion is quite guessable, but it's really hard to prove.

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

    Same, I've spent 15 minutes after writing a solution trying to prove it, shouldn't have done that.

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

    Ah funny, I just commented a similar thing below. I noticed but gave up on proving. I tried to write a solution that doesn't assume that, but I think it's really hard/tedious because of the $$$a[i]$$$ which are already equal to the mean.

    I feel like this type of thing, where some proof detail is quite hard, happens somewhat often. It kind of destroys me psychologically in contest, because I don't believe in my solution anymore.

    But other people can reliably umm... not have this problem I guess. I would like to know how lol.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it -25 Vote: I do not like it

      For me it is a bit instinctual. Ideally, I'd like to prove it in my mind or on paper before submitting, but I think sometimes that is a waste of time. If I have convinced myself beyond reasonable doubt then I simply submit. Like in this problem, I didn't feel that I needed to prove it, it just felt very natural to me that it was possible.

      I think this really depends on if you are a very mathematical person or not. I'm somewhere in between but I've had students on either end of that spectrum and their method works for them, but is a bit too extreme for my taste.

»
3 weeks ago, # |
  Vote: I like it +38 Vote: I do not like it
1B1
»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

So fast! Thanks!

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

My solution for Div1 B1/B2 was (I think?) a bit simpler than the editorials. Basically, similar to the editorials we can get two numbers a and b where we must give a and receive b. This can be transformed into, if we gained b, we send a. This is kind of like a graph where there are n edges, each representing a transfer that needs to happen. Then, to check if this graph is valid, it's quite easy. All you have to do is check if the graph can be turned into a bunch of cycles that do not reuse edges. It's very similar to finding an Eulerian circuit, and the restriction for that (for directed graphs) is that the indegree and outdegree must be the same. Something important is that in the case of the number equalling the average, the edge is a self-edge but can be placed anywhere, and as long as you visit a node, it works. Then, for B2, note that if the distance is a power of two then you can change two operations into one. The change to the degree array is +2 -1 or -2 +1 so you can loop downwards and apply changes when needed if possible.

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

in problem A div2, when n is odd , if I perform [n,n] once instead of performing [n-1,n] twice, it should give the correct answer right? as a[n] ^ a[n] = 0 .

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

    Well no. Operation for [n, n] will do nothing. Think of it this way, operation[1, 2] is a[1] ^ a[2], operation[1,3] is a[1] ^ a[2] ^ a[3] then operation[1,1] will be a[1], that's it, no more xor taken from there. It is range, so range(1, 3) contains 3 elements, range(1,1) contains only 1 element.

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

      I got your opinion, but by following their definiton, try to just use their formula you will get a[n]^a[n], it costed me frustration and two wrong answers :)

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

      but the definiton said l can be equal to r. for an array 1,2,3,4,5,6,7 if i perform 7 ^ 7 , it should be 0 right? hence performing an operation n n (n ^ n) operation should replace the last value with 0 right?

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

    n,n just means the xor of the subarray (n,n) and you are replacing an with an only not by an^an;

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

    Nope, because you don't XOR a[n] twice. The XOR in the range [n, n] would just be a[n], leaving the array unchanged.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it -9 Vote: I do not like it

      why? check the definition that they gave: Let s=al⊕al+1⊕…⊕ar right? and they said l<=r suppose l==r s=al xor ar no?? I actually got two wrong answers because of this! please prove me wrong :)

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

        I see your point, but I think that's just standard mathematical notation: for example, I think you agree if I say that the sum of the numbers from 1 to n is n(n+1)/2, right? But according to your argument, for n = 1 it should be 1+1 = 2.

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

          if we put n=1 in the formula blindly we will get it equal to 1 , not the same with their definition

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

            exactly.

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

            Yeah, but the formula is not what I focused on. I just wanted to point out that when we talk about the sum of the numbers from 1 to n we typically denote it as $$$1 + ... + n$$$. This notation means "1" and not "1+1" when $$$n=1$$$.

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

      exactly.. at the end it will be 0^a[n] i.e. a[n]

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

    bruh... a[n] ^ a[n] =0 is correct... but if n is odd you will end up with 0^a[n] (i.e. a[i])..which could be a non zero number

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

    Fill in the missing expression in the sequence!!! 95% fail!!!

    $$$\underline{\qquad}$$$, $$$1\oplus2$$$, $$$1\oplus2\oplus3$$$, $$$1\oplus2\oplus3\oplus4$$$, $$$\ldots$$$

    Hint: The answer is $$$\textbf{not}$$$ $$$1\oplus1$$$!

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

" Thus, if there exists a possible solution, the number of candies each person receives and gives away is determined for ai≠s . If an equation has no solution, then obviously the answer is "No". "

In Div1 B1, how can we prove/find out, that the equation has no solution??

UPD : Understood

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

Video Editorial for problem A,B,C,D1

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

Why does only taking good interval give the min amount of operations on F?

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

It appears that there are some typos in the editorial for B2. I believe these are the correct formulas:

For $$$x \leq cntDS_i$$$:

  • $$$cntS_i := cntS_i + x$$$
  • $$$cntS_{i+1} := cntS_{i+1} + cntDS_i - x$$$
  • $$$cntT_i := cntT_i + cntDS_i - x$$$

For $$$x \leq cntDT_i$$$:

  • $$$cntT_i := cntT_i + x$$$
  • $$$cntS_{i-1} := cntS_{i-1} + cntDT_i - x$$$
  • $$$cntT_i := cntT_i + cntDT_i - x$$$
  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I'm still confused about why the last 2 lines haven't kept a symmetrical relationship with the first fomula... just like:

    • $$$cntT_{i+1} := cntT_{i+1} + cntDT_i - x$$$
    • $$$cntS_i := cntS_i + cntDT_i - x$$$

    can anyone explain this for me? :)

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

Can anyone explain why does the solution to problem A (Div. 2) works?

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

    For this problem I first considered if each of the $$$a_i$$$ are either $$$1$$$ or $$$0$$$, since it helps to think about the most extreme cases first sometimes.

    Then notice that $$$1\oplus 1\oplus\cdots\oplus 1 = 0$$$ if the number of $$$1$$$'s is even, otherwise it's equal to $$$1$$$.

    Also notice that $$$0\oplus 0\oplus\cdots\oplus 0 = 0$$$ for any number of $$$0$$$'s.

    So clearly, if $$$r-l+1$$$ is even, then performing the operation on $$$a_l,a_{l+1},\dots,a_r$$$ will either make them all equal to $$$0$$$, or $$$1$$$, and then performing the operation again must always make $$$a_l=a_{l+1}=\cdots=a_r=0$$$.

    But then the same must be true for any values of $$$a_i$$$, not only if they are in $$$\{0,1\}$$$, since the same will happen for all of the bits of the numbers.

    So if $$$n$$$ is even, then we can just do the operation twice on the entire subarray.

    If $$$n$$$ is odd, we perform the operation twice on the first $$$n-1$$$ elements, and then twice on the last $$$n-1$$$ elements to ensure that all the numbers in the array are $$$0$$$.

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

For 1869A — Make It Zero, why couldn't you do something like cout<<n<<" "<<n<<endl; ?
Edit: I didn't see the posts above my bad

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

    That doesn’t do anything. It replaces the last element just by the last element itself. We need to replace it by 0.

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

      but your doing XOR to the same value, so doesn't that make it 0. Like 8 ^ 8 = 0

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

      Actually, my bad, I see why. I thought that doing cout<<n<<" "<<n<<endl; meant that you replace the nth value with arry[n] ^ arry[n] = 0.

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

I can't understand Div2D2 solution. Can someone explain plz?

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

thanks for fast tutorial.

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

bad cones\

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

For this example in Q D1/B1

1 3 6 4 8

We are getting YES , can anyone tell me method of distribution of candies

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

    Test case -> 1 N -> 3 [6,4,8]

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

    Last person gives 4 candy to the first one; First person gives 4 candy to the second one; Second person gives 2 candies to the third one.

    First person: 6-4+4=6 Second person: 4-2+4=6 Third person: 8-4+2=6

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

In div1A / div2C Test case 25 is : 2 4 According to the solution the resultant matrix is [[0 1 2 3], [1 2 3 0]]

v[i] : 2 0 0 1

s = mex(v[i]) = 3

But correct answer for this test case is 4 How is this possible or am i missing something???

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

    Bro you are correct by ur proof. The mex of 2 4 is 3. But ur code is printing 4.

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

In problem Div1 C what is $$$f_{i,j}$$$ (one end being $$$i$$$ — what is it?) and what does this mean: The only difference is that only one $$$f_{i,j}$$$ is not $$$0$$$ under this circumstance and we can solve it in $$$O(log^2n)$$$?

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

My approach to Div1B1/Div2D1 and Div1B2/Div2D2, with only 1D vectors and 1D maps and no graphs (though one can argue there is an implicit graph being considered):

Net Gain: The total sum never changes, so to make all values equal, each value must become equal to the average. If the average is not an integer, answer is NO. After calculating the average, we can easily determine, for each value, what number needs to be added/subtracted to reach the average. Each value has a required "net gain" to reach the average. For values above the average, the net gain is negative (since they actually need a net loss).

Validity of Net Gain: In order to reach the average, the net gain must be expressible as the difference between two powers of 2. For example, a net gain of 12 can be achieved by receiving 16 candies and giving 4 candies. But a net gain of 5 cannot be achieved. Checking whether a net gain value is valid, as well as determining what the respective powers of 2 are, is easy when considering the numbers in binary. Assuming $$$x > y$$$, then $$$2^x - 2^y = 2^y (2^{x - y} - 1)$$$ will have $$$(x - y)$$$ 1s in a row, followed by $$$y$$$ lagging 0s. Utilizing the __builtin_clz and __builtin_ctz functions can help in quickly determining whether a net gain value is valid or not, as well as what the corresponding powers of 2 are (but there are many other ways to do this as well). Note that we would also have to deal with scenarios for $$$x = y$$$ (net gain of 0) and $$$x < y$$$ (net gain is negative, but we can inspect the binary representation of the absolute/negated value instead).

Fulfilling all Net Gains (Easy Version): In the Easy version, if a net gain value is valid, i.e., expressible as $$$2^x - 2^y$$$, then the only way to achieve this net gain is to receive $$$2^x$$$ candies and give $$$2^y$$$ candies. To check whether this is possible for all values, I used a simple map mp, where for a positive integer p, an entry mp[k] = p indicates there are p values that want to give k candies, while an entry mp[k] = -p indicates that there are p values that want to receive k candies. For each value where net gain is non-zero, I determine $$$2^x$$$ and $$$2^y$$$, increment $$$mp[2^y]$$$ and decrement $$$mp[2^x]$$$. If all net gains can be fulfilled, then all map entries should be 0 at the end, since the number of people who want to give $$$k$$$ candies must match the number of people who want to receive $$$k$$$ candies, for all $$$k$$$.

Correctness: Having all map entries be 0 is a necessary condition for Yes, but is it sufficient? We don't have to worry about values with net gain 0, because we can simply have them pass a candy around to each other. Even if there is only one value with net gain 0, this person can be placed as a relay between someone who needs to give some candies to another person. The hard part was on checking whether there will always be someone who has enough candies to start the chain. Apparently this is always satisfied (according to the editorial), and while I don't have a proof either, I intuitively observed that the person with the largest number of candies in each cycle should have enough to start the chain.

Easy Submission: 222779990 (it has some artifacts from when I was trying to check whether it's always possible to start the chain, like sorting the values in reverse-order, and setting a flag when somebody has enough to do so, but this doesn't account for multiple independent chains)

Hard Version: If a valid net gain, $$$2^x - 2^y$$$ cannot be be written as $$$\pm 2^z$$$ for integer $$$z$$$, then the only way to achieve this net gain is through receiving $$$2^x$$$ candies and giving $$$2^y$$$ candies, which we have already dealt with in the Easy version. But if $$$2^x - 2^y = \pm 2^z$$$, then there are actually two options. Without loss of generality, if $$$2^x - 2^y = 2^z$$$, then we can either (A) receive $$$2^x$$$ and give $$$2^y$$$, or (B) simply receive $$$2^z$$$ and give nothing. Note that, in this case, we must have $$$x = z + 1$$$ and $$$y = z$$$.

How do we decide which of the two options to choose? My approach was to first deal with the values that have only one option (like Easy Version) and stores the values with two options in a separate vector to handle later. The map mp may have some non-zero entries at this point. For the remaining net gains (which are powers of 2, or their negations), I sorted them from highest absolute value to lowest absolute value. Let's say the largest value has a net gain of $$$2^z$$$. I consult the map to see if anybody else wanted to give $$$2^{z + 1}$$$ candies. If yes, then choose option A, i.e., receive the $$$2^{z + 1}$$$ and give $$$2^z$$$. If there is no such person, then choose option B, i.e., receive $$$2^z$$$ only and give nothing. The case of net gain $$$-2^z$$$ is handled similarly. In any case, we update the map and move on to the next value.

Correctness: The sorted descending order is crucial. When we process the value with net gain $$$2^z$$$, if there really is some value that wants to give $$$2^{z + 1}$$$ candies, then the only valid recipients are those with net gain $$$2^z$$$, since the remaining values afterwards would have smaller powers of 2, and cannot receive $$$2^{z + 1}$$$ candies. So option A is always valid in such a scenario.

But what about the scenario where we process a value with net gain $$$2^z$$$ and nobody wants to give $$$2^{z + 1}$$$ candies? Sometimes, option A might be valid here, i.e., receive $$$2^{z + 1}$$$ and give $$$2^z$$$, but this requires that there is a $$$-2^z$$$ value later on who will also choose option A, i.e., give $$$2^{z + 1}$$$ candies, but such a value would also have to receive $$$2^z$$$ candies, so these two people can simply swap with each other only. This is equivalent to both people choosing option B. Therefore, choosing option B is always guaranteed to work in this scenario (whereas option A would fail if there is no $$$-2^z$$$ later).

Hard Submission: 222851644 (still has the artifacts from Easy)

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

No matter what I do, I can't find the bug in my problem 1C. This is the first time I am completely unable to understand where my mistake is, even though my code can't pass the sample. I'm confused because the first three examples passed and there were no issues with overflow or out of bound or anything when I submitted it to Codeforces. Please, can someone help me take a look? I've been working on it all day. 222871376

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

Hi could someone please explain how to find the values of x and y in Div2B1?

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

May anyone explain the bit operations in the editorial of Problem D1 in div.2? I can't quite understand it

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

Thanks for the great contest!

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

I think B1 is an amazing problem.

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

I posted a video editorial of problem C from Div. 2, I hope you enjoy it and find it interesting.

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

D2 is great

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

thanks for clear editorial ^^;

Nice E

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

Can someone tell me why my code is giving TLE ? I'm also solving the question in O(t*(n+k)) time complexity.

My submission : https://codeforces.com/contest/1869/submission/222959644

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

Problem A

If your n is even :

Say you have:

n=6

[a,b,c,d,e,f]

a^b^c^d^e^f =X

[X,X,X,X,X,X]

Now if you do the operation one more time on the entire array,

X^X^X^X^X^X= 0

[0,0,0,0,0,0]

So the no of operations used are 2. (1 to n) (1 to n)

If your n is Odd:

Say n is 5

[a,b,c,d,e]

a^b^c^d^e=U

[U,U,U,U,U]

So U^U^U^U^U=U [U,U,U,U,U]

SO WHAT WE DO IS : IF YOUR N IS ODD WE XOR 1 to N-1 and again N-1 to N

[a,b,c,d,e]

So a^b^c^d=U

[U,U,U,U,e]

And now again from 1 to n-1 U^U^U^U=0

SO ARRAY BECOMES

[0,0,0,0,e]

NOW from n-1 to n

0^e=e

[0,0,0,e,e]

Again n-1 to n

e^e=0

SO NOW IT BECOMES

[0,0,0,0,0]

So if n is odd then output 4 (1 to n-1) (1 to n-1) (n-1 to n) (n-1 to n)

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

In A why we are taking 2 cases for even and odd when we can simply apply XOR on the whole array twice and get the ans?

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

In Problem D1, can someone please explain why the following input has output 'No'

1

3

16 10 10

From what I understand, a1 can give 4 candies to a2 and then a2 can give 2 candies to a3 which should make the arrray

12 12 12

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

    nvm, I got it. I misread the statement where it says that it is mandatory to receive candy for each person.

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

can someone help why its MLE 18 Div2C? https://codeforces.com/contest/1869/submission/223144068

upd:solved i'm changed writing in vector when m>n solution: https://codeforces.com/contest/1869/submission/223145308 anyway i dont get why first solution MLE

»
2 weeks ago, # |
Rev. 2   Vote: I like it -9 Vote: I do not like it

💚

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

dX ain't so happy 'bout problem D&F... felt it's actually okay:)

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

B2's tutorial needs a fix. Should be $$$a_i + 2^{x_i}$$$

»
11 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Why i have to take even numbers of element to do xor operation. Why cant i do 1 to n xor operation two times in every case.(in https://codeforces.com/contest/1869/problem/A)

»
10 days ago, # |
  Vote: I like it -21 Vote: I do not like it

老子真草了,题出这么难干什么啊?

»
10 days ago, # |
  Vote: I like it -20 Vote: I do not like it

写题解不写完整是吧,证明留给读者,我真艹了你*了

»
8 days ago, # |
  Vote: I like it -11 Vote: I do not like it

这D2的代码和题解真的弄的是一道题?后面的公式全是错的,真的,不想写可以不写的