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

Автор YouKn0wWho, 5 часов назад, По-английски

Thanks for participating in the contest blobheart. We hope you liked the problems. We would love to hear your feedback in the comments.

If you find anything wrong in the editorial which is more likely to happen because we have written a rather long editorial to make you understand the solutions better, then comment below.

We also tried to write the thought process of how you can come up with the solution for the easier problems. The approach I followed is similar to what the current AI agents do. They first generate some thoughts, then do some actions, then gather observations, and repeat the process until they find the solution. Hope you will like this approach.

Also, don't forget to upvote the editorial. See you in the next contest!

Also, please rate the problems after checking the editorial. Because otherwise you might have solved it in a very cumbersome way that you will end up hating the problem.


How did you find the contest?
Which problem is your most favourite?
Which problem you hate the most?

Also, huge props to redpanda for creating awesome manim video editorials for problems A to D. Check it out here: https://www.youtube.com/watch?v=elRvvUbk1J4

2039A - Shohag Loves Mod

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039B - Shohag Loves Strings

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039C1 - Shohag Loves XOR (Easy Version)

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039C2 - Shohag Loves XOR (Hard Version)

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039D - Shohag Loves GCD

Author: YouKn0wWho

Tutorial
Code (Solution 1)
Code (Solution 2)
Rate the Problem

2039E - Shohag Loves Inversions

Author: YouKn0wWho

Tutorial
Code
Code (by wyrqwq, without initial casework)
Rate the Problem

2039F1 - Shohag Loves Counting (Easy Version)

Author: YouKn0wWho

Tutorial
Code (by LipArcanjo)
Rate the Problem

2039F2 - Shohag Loves Counting (Hard Version)

Author: YouKn0wWho

Tutorial
Code (unoptimized)
Code (optimized)
Rate the Problem

2039G - Shohag Loves Pebae

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039H1 - Cool Swap Walk (Easy Version)

Author: wuhudsm

Tutorial
Code
Rate the Problem

2039H2 - Cool Swap Walk (Hard Version)

Author: wuhudsm

Tutorial
Code
Rate the Problem
  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

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

Even after solving A,B my rating went from 999 to 994 why?

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

    Many people solved C1 and higher difficulty problems, so your rank dropped to 6000+ out of ~9100+ which gets calculated as a slightly lower performance than your last rating.

    You can check more on rating calculation at https://mirror.codeforces.com/blog/entry/20762 or try out some CodeForces Rating Predictor for a better view on the rank vs rating.

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

      Oh! Okay I guess I have to grind more to reach pupil

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

This round was a peace of shit

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

Bitmask + XOR = Pain

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

Shohag Loves Bitmasks :')

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

Shohag loves OEIS (specially A079752)

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

bro changed all the bad downvotes to average, disgusting

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

_LonggVuz. bitmasks almost killed me, the problem D saved my rating ._.

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

F2: Cool problem, but why set the time limit so tight? The model solution (and most of the contestants' solutions) run in over 3s, and I couldn't get my solution to run much faster than 5s during the contest. :(

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

I liked B, C1, C2, E. Thanks for the round. H also looks interesting

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

Anyone else solved C2 using binary search ? 😂 😂

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

What's the approximate rating of D?

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

The problem E does not request even ability to think. We need only slow solution that can calculate the number of possible arrays without modulo for $$$n < 14$$$ (which is easy to implement) and Wolfram Mathematica function FindSequenceFunction, which attempts to find a simple function that yields the sequence, when given successive integer arguments. Using the slow solution, we get the following sequence $$$(0, 1, 2, 5, 19, 102, 682, 5321, 47071, 464570, 5057058, 60166913, 776595027)$$$ of the answers. Now, we can use FindSequenceFunction to obtain the solution:

FindSequenceFunction[{0, 1, 2, 5, 19, 102, 682, 5321, 47071, 464570, 
  5057058, 60166913, 776595027}]

It gives the answer:

DifferenceRoot[Function[{y, n}, 
    {1 + (2 + n)*y[n] + (-3 - n)*y[1 + n] + 
          y[2 + n] == 0, y[1] == 0, y[2] == 1, y[3] == 2}]]

It is the recurrence relation, which can be simply coded: 292998575.

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

Some learnings as an Author: Judging by the votes and comments it seems like people mostly liked the problems individually but didn't like that most problems were mathy and didn't have enough variations. So I will try to keep that in mind and will add more variations to the contest in the future.

And I am also not happy that during the contest we found out that some people found the second difference/derivative of the sequence on OEIS. I searched on OEIS before but couldn't find it (I saw that it's not there but I didn't notice that there are some deltas matching for another sequence that were written on the OEIS page, I guess I have to be better regarding finding sequences on OEIS). Otherwise, we would have definitely modified the problem. Sorry for this issue.

Hopefully next time I will try to bring a more diverse round. Thanks for participating in the round!

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

Why Shohag loves so much number theory, although problems are really good.

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

Bro how does D have more solves than C2

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

Hello every one I have been trying to learn more about mobius function and it’s application but I couldn’t find any resources Can some one help me in this matter ?

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

The time limit of F2 is very bad. The solution which runs in $$$\sum_i \sigma^2(i)$$$ should have passed easily. It should not be a close call. The optimisations into $$$\sum_i \sigma(i) \times p(i)$$$ do not add any new ideas, and the constraints suggest there is a solution faster than this.

The inclusion of both C1 and C2 may make sense in terms of round balance (which frankly, is still pretty bad), but I don't see it being a good idea to test the same skill-set twice.

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

There's a cute solution to D.

Let cnt(x) be the number of divisors of x, not including 1 and x.

Then, set answer[i] to be equal to S[m - cnt(i)].

That's it :)

And if the index is ever equal to zero or negative (assuming indexing starts at 1), then output -1.

The reasoning stems from the same thoughts as the editorial, though I am too tired to write out a formal proof.

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

My solution of how managed to solve C2 but also at the same time failed miserably at it. I am able to skip an observation, but with paid a serious price in terms of implementation.

We need to check for $$$x| x \ xor \ y$$$ or $$$y | x\ xor\ y$$$. The second case is only possible if $$$y <= 2x$$$. We focus on the first case, rewrite $$$x xor y$$$ as $$$x + y - 2 (x\ and\ y)$$$. Let $$$k$$$ be the smallest integer such that $$$2^k > x$$$. Then, the value of $$$y\ mod\ 2^k$$$ is enough to determine $$$x\ and\ y$$$. For each $$$0 \leq c < 2^k$$$, we consider $$$y = a2^k + c$$$, this becomes a certain divisbility condition imposed on $$$a$$$, which can be solved with a certain CRT. This solution is now $$$O(x \log x)$$$.

To optimise, It can be seen (by looking at the implementation), that the required extended modular inverse to calculate is same for every $$$c$$$, so the $$$log x$$$ time to calculate inverse is common. This gives a solution of $$$O(x)$$$.

Being able to come up with a highly technical alternative solution, but unable to actually follow through with it in implementation, turns out to costed me greatly in this round. Submission: 292984478.

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

I might have a little less mathy and simpler explanation for C2.

Let’s say x XOR y is a multiple of x.

So,
x XOR y = c * x (where c is any integer >= 0).

  1. If c = 0:
    x XOR y = 0 implies x = y (which is a valid case).

  2. If c = 1:
    x XOR y = x implies y = 0 (which is an invalid case since y > 0).

  3. If c = 2:
    x XOR y = 2 * x implies y = (2 * x) XOR x.

In this case, y > x, because the leftmost bit in 2 * x is not set in x. Therefore, the XOR operation introduces a set bit that makes y > x.

Thus, x XOR y is a multiple of x if and only if y > x.


Now, consider y = (c * x) XOR x for some constant c.

  • From this, we can deduce:
    y <= c * x + x and y >= c * x - x.

  • So, for any multiple of x, the value of y can differ from c * x by at most x.

To solve this:

  1. Choose all multiples of x that are <= m.
  2. For the last multiple, check to the left and right of it to ensure the corresponding range of y is valid within m.

Personally, I used binary search to find the largest y such that y = (c * x) XOR x <= m. Then, I checked the next two multiples of x beyond this point to see if their corresponding range of y also falls within m.


Dividing the Range of y

Since 1 <= y <= m, we can split the range of y into two parts:

  1. For 1 <= y <= x:
    Here, we can simply loop over all values of x in O(n) and check if x XOR y is divisible by x or y.

  2. For x < y <= m:
    From the earlier reasoning, x XOR y is divisible by x. But not divisible by y, as shown in the editorial in Case 2.

This approach ensures correctness and efficiency with a O(n) solution.

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

xor is like subtraction without borrowing.(problem c2 editorial correction)YouKn0wWho