Блог пользователя Rudro25

Автор Rudro25, 4 года назад, По-английски

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.

Разбор задач Noobs Round #2 (Div. 4) by Rudro25
  • Проголосовать: нравится
  • +129
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится

    this will also work!

    cout << ((a | b) == (a + b) ? "No" : "Yes") << "\n";
    
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for the round and quick editorial

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for the round waiting for the next one

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

Nicely done, thanks for the contest!

»
4 года назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      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 года назад, # ^ |
        Проголосовать: нравится +2 Проголосовать: не нравится

      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 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

Thanks for the contest, had fun doing it!

»
4 года назад, # |
  Проголосовать: нравится +14 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Nice Contest..problem set was really good.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Sure! My bad

      • »
        »
        »
        »
        4 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        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 года назад, # ^ |
            Проголосовать: нравится +1 Проголосовать: не нравится

          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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    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 года назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

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

Problem F submission

Great tasks tho!

»
4 года назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

IGNORE

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
9 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for the contest!