Rudro25's blog

By Rudro25, 4 years ago, In English

Contest link : https://codeforces.net/gym/102942

Announcement link : https://codeforces.net/blog/entry/87209

Finally, The round is over smoothly :) We hope everyone had fun and enjoyed the contest!

A. Directional Move

Tutorial
Solution
Tester Solution

B. Make All Odd

Tutorial
Solution

C. Team

Tutorial
Solution
Tester Solution

D. XOR Game

Tutorial
Solution
Tester Solution

E. Password

Tutorial
Solution
Tester Solution
Tester Solution 2

F. Offer

Tutorial
Solution
Tester Solution

-If have any more query, then please comment.

  • Vote: I like it
  • +129
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

thanks for this contest and hope for more contest like this.

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

Great round. For D, if x and y have no common bits then answer is NO else YES. So this will also work

if(x & y) cout << "Yes";
else cout << "No";
  • »
    »
    4 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    this will also work!

    cout << ((a | b) == (a + b) ? "No" : "Yes") << "\n";
    
  • »
    »
    4 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    thank you for this . I came up with the same logic , but didn't know how to proceed with bit manipulations.

    So used the basic method to calculate every bit by n%2 and check whether both of them are 1 or not

    if(a%2 && b&2)
    {
    cout<<"Yes"
    return;
    else
    a=>>1;
    b=>>1;
    }
    
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for the round and quick editorial

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

Thanks for the round waiting for the next one

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

Hoping to solve upto D in div2 contest also some day. btw thanks for this contest and hope for more contest like this.

»
4 years ago, # |
  Vote: I like it +15 Vote: I do not like it

Nicely done, thanks for the contest!

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

E was really a good problem for learning dp, thanks for the round.

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

We can also solve E with combinatorics. Combination with repetition to be exact. Suppose the string is like, 1----5. We can place any digit from this, {1,2,3,4,5} set in increasing order in 4 place between 1 and 5.

Let, n = number of place to fill. m = size of the set. Possible ways will be (n+m-1) Choose n.

For practice: https://codeforces.net/contest/1288/problem/C

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

    I thought on similar lines but wasn't able to get my code working as intended. I'd appreciate it if anyone out here could look into the following submission.

    Link: https://ideone.com/U8cjmP

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

      Try checking the validity of the result explicitly.

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

      The problem is with the size of your fac array which is 100005 but according to the problem n<=10^6 which makes n+k-1<=100009(and it is less than 100005).

      I changed 100005 to 100020 and it got Accepted

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

    Thanks for the formula, I got stuck at this and couldn't find this formula. Can you please provide me an explanation or a link where this formula can be find? Thanks for the given problem too.

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

      Stars and bars

      Imagine you need to fill a sequence of integers of size $$$10$$$ using only $$$1$$$, $$$2$$$, or $$$3$$$ so that the sequence is non-decreasing. As they are non-decreasing, all $$$1$$$'s have to appear in front of all $$$2$$$'s and so on, so we don't need to care about the order of these integers and we need only the number of occurences of each $$$1$$$, $$$2$$$, and $$$3$$$. Thus, we need to find number of solution of: $$$count_1 + count_2 + count_3 = 10$$$, with $$$count_0, count_1, count_2 \geq 0$$$.

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

      Check this out: https://www.youtube.com/watch?v=4_je4mXUCGA Hope it will be helpful. I learned it from Coursera. Someone uploaded the video in YouTube too.

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

      Consider this example:

      1 — — — 6

      In this we have to fill 3 places and to fill those 3 places we have 6 elements. Now observe that we only need to choose the elements with which we want to fill the gaps. We don't need to decide the order as that is fixed.

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

    I also tried to solve it with combinatorics. 105596767 This is the code it's failing test case 4. So can you help? if you find something. Thanks in advance.

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

Thanks for the contest, had fun doing it!

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

Please make the submissions public, or atleast the testcases. It helps a lot in debugging silly mistakes.

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

    I already told this secondthread sir. May be he will open soon , if possible sir.

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

Could anyone explain F in a more detailed way? It would be much appreciated.

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

    It's just 2 pointer approach, we can keep on increasing our right pointer while maintaining frequency and cost, until the cost becomes greater than k. At this point we can start incrementing our left pointer and decreasing the cost. The number of elements will right-left+1. Now we keep on repeating the prcoess.

    Code
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

If in problem D, we were asked to maximize the score of Bob, how will we solve it ?

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

    I think You can iterate from the highest to lowest bit, and try to set it, if possible.

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

The contest was great! Although I had come up with a similar idea as editorial, I had a hard time proving D during contest. I still can't wrap around why case 2 always is true. Could anyone please explain?

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

Nice Contest..problem set was really good.

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

Very nice contest! Want more! Especially thanks for the good E task.

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

The F can also be solved using the bit + binary lifting technique.

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

can you please add more test cases? bacause it is just checking with one test case and getting accepted?

so now i don't even know whether my solution is correct or not?

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

    You have the permission to see only 1 test case, sir. May be it's the 'gym' contest rule.

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

For C, why is the following approach incorrect? Answer is at least equal to elements >=k. Now put other elements in a list and sort it. Now iterate over every element, for every a[i], use lower_bound() on k-a[i] in range [i, list.size()] to find if such element exists. If it does, mark it used and increment answer. Why does this give a WA?

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

    can you please provide the code by spoiler! no permission to see other submission :(

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

      Sure! My bad

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

        Failed test case: 1 10 5 1 3 2 1 4 3 4 2 3 1

        Expected: 4 but found 6.

        May be the problem is — When you find a pos by lower_bound it can be also used before but you not checked that. may be you can use set and remove every used element then you can use lower_bound easily.

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

          Ah right, I think the problem exactly is what you pointed out, I should definitely be removing those used values from my list. Thanks! Orz

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

Let's consider a variation of problem F. Now in the subsegment [l,r] instead of making the cost of all repeating elements in that subsegment zero if we were allowed to take only one of the repeating elements in that subsegment and make its cost equal to zero. Rest all the conditions remain same as mentioned in the problem F. Then can someone please provide an insight on how we could have solved it.

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

Hello , Thanks for this Contest . Can you Please Update the Settings so that we can we view all the test case , My Code for F gave wrong answer on test case 3 but I cannot access that test case . Thanks .

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

    secondthread sir told that's may be impossible sir. but you can provide your code, i can check that by using polygon which on failed (:

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

We need more contests like this. Contests like today's destroy us and you pick us up. Thanks for organizing this man!

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

So, my understanding of the solution of $$$D$$$ is as follows:

If $$$a$$$ and $$$b$$$ are given such that there are no common bits between them, the answer is $$$NO$$$, because there are no 2 integers $$$1 \leq c \leq a,$$$ $$$1 \leq d \leq b$$$ s.t. their xor will be strictly greater than the xor between $$$a$$$ and $$$b$$$.

If $$$a$$$ and $$$b$$$ are given such that there are common bits between them, the answer is $$$YES$$$, because we can always find 2 integers $$$1 \leq c \leq a,$$$ $$$1 \leq d \leq b$$$ s.t. their xor will be strictly greater than the xor between $$$a$$$ and $$$b$$$.

But I don't understand why this should always be true (i.e. for 2 integers $$$a$$$ and $$$b$$$ s.t. there are common bits between them, why is it that we can always find 2 integers $$$1 \leq c \leq a,$$$ $$$1 \leq d \leq b$$$ which don't have common bits between them, s.t. their xor will always be strictly greater than the xor of $$$a$$$ and $$$b$$$), can anyone please provide a more detailed explanation of this or a proof?

Edit: deleted some erroneous stuff I thought was correct..; also, thanks a lot @doubleux, that last paragraph (especially) really made it very clear and obvious that the "strategy" for the solution of $$$D$$$ would always work.

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

    Notice, that the maximum Xor between any two numbers is always less than their sum, the maximum arising when no two bits are common.

    Thus, if no bits are common, Xor of a and b is a+b, which is maximum that you can get using numbers less than them. Therefore no pair possible in this case.

    If the do have common bits, a Xor b will be 0 at that position. Now choose c same as a, while for d, change the bit at common position as 0. This will make that bit 1 in their bitwise Xor, thus making it larger.

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

I used the same logic and approach in F but got TLE, why Python why :'-)

Problem F submission

Great tasks tho!

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

I used the chorus property. a^b=c -> a^c=b so (c^d = (a^b)+somenum) -> (c^((a^b)+somenum)=d) And did 1<=somenum<=10. But why +10 was enough I don't understand. can open my eyes?

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

IGNORE

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

Video tutorial for problem D: https://youtu.be/y2ERMJFsyjg

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

please conduct more these type of contest . This is very helpful for beginners.

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

Thanks for the contest!