YouKn0wWho's blog

By YouKn0wWho, 5 hours ago, In English

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
  • Vote: I like it
  • -12
  • Vote: I do not like it

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

    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 hours ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

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

»
5 hours ago, # |
  Vote: I like it +71 Vote: I do not like it

This round was a peace of shit

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Bitmask + XOR = Pain

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Shohag Loves Bitmasks :')

»
5 hours ago, # |
  Vote: I like it +29 Vote: I do not like it

Shohag loves OEIS (specially A079752)

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

bro changed all the bad downvotes to average, disgusting

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

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

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

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. :(

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

    I agree. It's a cool problem but the time limit is too tight

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

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

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

Anyone else solved C2 using binary search ? 😂 😂

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

    I did. I found the highest y <= m, such that x^y is a multiple of x.

»
4 hours ago, # |
  Vote: I like it -8 Vote: I do not like it

What's the approximate rating of D?

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

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.

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

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 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

Bro how does D have more solves than C2

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

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 hours ago, # |
  Vote: I like it +4 Vote: I do not like it

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 hours ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

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.

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

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.

»
110 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
35 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

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