Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

Автор Boboge, 5 месяцев назад, По-английски

Thank you for participating! We hope you enjoyed the problems.

2237A - Destroying Towers

Idea: _ja Preparation: _ja & quacksaysduck

Tutorial
Implementation

2237B - Annoying the Ghost

Idea: quacksaysduck Preparation: _ja & quacksaysduck & Boboge

Tutorial
Implementation

2237C - Duck Surplus

Idea: quacksaysduck Preparation: Boboge

Tutorial
Implementation

2237D - Fullmetal Bitchemist

Idea: zeemanz Preparation: __baozii__

Tutorial
Implementation(python)

2237E - Permutation Commutation

Idea: _ja Preparation: Boboge

Tutorial
Implementation

2237F - Paint the Array

Idea: StarSilk Preparation: StarSilk & Sugar_fan

Tutorial
Implementation

2237G - Send GCDs

Idea: _ja Preparation: Boboge

Tutorial
Implementation

2237H - Slime and Queries

Idea: StarSilk Preparation: StarSilk & Sugar_fan

Tutorial
Implementation

2237I1 - DBFS Order (Easy Version)

Idea: StarSilk Preparation: StarSilk & Sugar_fan & Boboge

Tutorial

2237I2 - DBFS Order (Hard Version)

Idea: StarSilk Preparation: StarSilk & Sugar_fan & Boboge

Tutorial
Implementation
  • Проголосовать: нравится
  • +88
  • Проголосовать: не нравится

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Auto comment: topic has been updated by Boboge (previous revision, new revision, compare).

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

D absolutely fried me man... Im quite happy with my +16 tho!

»
5 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +29 Проголосовать: не нравится
Alternate Solution to F
»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится -50 Проголосовать: не нравится

.

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

I went to sleep early =(

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

in D, because our final value is either +1 or -1 we can deduce that the total sum is 3x+1 or 3x-1.

After this, noting that alternating strings don't work or that there has to be at least one pair of adjacent equal characters suffices. My implementation

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

    can you explain the part of ur code where you count the correct substrings ~~~~~ int r = n, ans = n; for(int i = n — 1; i > 0; i--) { if(s[i — 1] == s[i]) { while(r > i) { f[pref[r--]]++; } } int here = f[(pref[i — 1] + 1) % 3] + f[(((pref[i — 1] — 1) % 3) + 3) % 3]; ans += here; } ~~~~~

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

      I maintain a pointer r which stays at position i such that $$$ s_i = s_{i-1}$$$ and if I get to such i, I decrease my pointer to that point while updating the map. Finally, as I said above the valid sum is $$$ 3x \pm 1 $$$, I am just calculating those values in the variable here. $$$ 3x \pm 1 \equiv \pm 1 \mod 3 $$$

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

man i got cooked by B so bad

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

man i got cooked by D so badly

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

D led to my -73 =(

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

Really enjoyed the contest And problem D is fire ,,, happy to solve it

»
5 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Is problem B — 2237B - Annoying the Ghost significantly harder if the problem is to change from array $$$b$$$ to $$$a$$$, instead of $$$a$$$ to $$$b$$$?

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

B is extremely difficult... ...

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

Is there a way to solve D using DP, trying to store the count of beautiful substrings ending at 0 or 1, and also storing bad/alternating substrings, then adding them up for each index?

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

    Plenty of edge cases arise. I tried this approach over and over but was always able to think of a case where it fails.

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

    Yes, there is a way for D using just DP and I did exactly that in the contest. But the issue is I used 7 DP arrays.

    Nevertheless, here is my solution.

    Let $$$dp_{x}[i]$$$ denote the number of substrings ending at i, such that it is non alternating and the difference of counts of $$$0$$$ and $$$1$$$ is $$$x \space mod \space 3$$$. ($$$x = 0,1,2$$$)

    Let $$$dp_{xy}[i]$$$ denote the number of substrings ending at i, such that they are alternating and they start at $$$x$$$ and end at $$$y$$$. ($$$xy = 00,01,10,11$$$)

    Then loop through the string and at each character try adding it to the previous substrings. Just keep in mind that a single character is considered an alternating substring.

    Here is my code for reference : 379415083

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

      Thank you for the solution. If you don't mind, can you please share how you arrived, or why you went in the direction of taking the difference of counts? Taking the difference of counts wasn't even remotely in my thinking space, when trying to solve the problem. I kept trying to find the count at each index by checking if adding a 0 or 1 to the previous subarrays will yield a beautiful one, and adding them with half the alternating subarrays.But I couldn't go in the direction of taking the counts, as I kept thinking count of each element won't matter since we're taking a subarray.

      • »
        »
        »
        »
        4 месяца назад, скрыть # ^ |
        ← Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        try to set up an equation to just observe the initial and final (potential/target) states

        we have two kinds of operations (-2, +1) and (-1, +2) on the pair (n, m) representing the number of 1s and 0s. say we did x and y of each operation and reached the final state of a single number lets say '1' for now.

        n-2x + y = 1

        m-2y + x = 0

        n-m-1 = 3 * (x-y) , meaning n-m = 1 mod 3.

        similarly for reaching a final state of '0' we get n-m = 2 mod 3.

        This means we can only reach final state of a single number of we have n-m != 0 modulo 3.

        Setting up the equations and playing around made me stumble upon this

»
5 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Sorry for the comment, I completely missed that given b is sorted.

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

it makes no sense that people with O(n^2) are passing B, those testcases are way too weak

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

not relevant to the solution of D but in D, is it true that for any binary string, if it is beautiful then it reduces to a unique value? Intuitively feels like that should be the case, but not sure how to prove it.

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

    Yes thats true(if I understood your question correctly) and here is my proof:

    Lets say $$$f^n(0)$$$ is the quantity of $$$0$$$ in some string $$$s$$$ after $$$n$$$ operations. The same with $$$f^n(1)$$$. It is easy to see that $$$f^{n-1}(1)-f^{n-1}(0) \equiv f^n(1)-f^n(0) \pmod3$$$(because -1-2 is 0 and 2-(-1) is also 0 by mod 3). So, we are assuming that string is beautiful so lets say that after $$$k$$$ operations we will end up with one symbol(WLOG lets say it is 1). So: $$$f^0(1)-f^0(0) \equiv f^1(1)-f^1(0) \equiv ... \equiv f^{k}(1)-f^{k}(0) \pmod3$$$

    But we know that since we only have one 1 and zero 0 at the end after $$$k$$$ operations, $$$f^{k}(1)-f^{k}(0)=1 \pmod3$$$

    If there was some combination where we can reach only 0 at the end after some $$$m$$$ operations, then with the same logic $$$f^0(1)-f^0(0) \equiv f^1(1)-f^1(0) \equiv ... \equiv f^{m}(1)-f^{m}(0) \equiv 0 -1 \equiv 2 \pmod3$$$

    So we have $$$1 \equiv f^0(1)-f^0(0) \equiv 2 \pmod3$$$ which is not true

    In less formal terms: Every single move you make changes the value of (count of 1s) — (count of 0s) by either $$$+3$$$ or $$$-3$$$. This means the remainder of this difference when divided by 3 never changes. Since a final 1 leaves a remainder of 1, and a final 0 leaves a remainder of 2, a string can never reduce to both. The final symbol is strictly predetermined from the very beginning.

    Feel free to ask if anything is unclear

»
5 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +3 Проголосовать: не нравится

Heyy

idk if i have enough knowledge regarding this but idk i noticed some of my known friends whom i know personally solving D in like 15 mins who are new to CF like me. I dont wanna accuse someone but i got suspicious and after contest tried GPT and it gave the correct passable code logic within like 1 min.

Can something be done because i was bummed out seeing 4k submissions on D during contest(though i know here div 1 ppl were there too this time) . i do agree that most would have independently solved it and me finding it tough isnt a benchmark for saying that others cant do it quickly but just in case can any measures be taken??

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Auto comment: topic has been updated by Boboge (previous revision, new revision, compare).

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Oh boy, I don't remember having so many alternative solutions

Problem C
Problem F
Problem G
»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

1k+ people solved E (╥﹏╥)

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится -26 Проголосовать: не нравится

E isn't hard but code is too long

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

How can I compute inversions in O(N log N) in problem B?

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

When testing the round, I found some optimizations that can be done on problem G to reduce the array length to $$$\left \lceil \frac{10n}{9} \right \rceil + 55$$$ and query count to $$$55n$$$, I think it's a pretty cool challenge to think about. Here's my solution:

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

I only accepted problem A,so I think I don't have enough programming level to take part in this contest.

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

D is such a cool problem.

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

i dont get editorial of B i see if we map a1 to bj instead of bi < bj and say some other element am comes for bi then then am <= bi < bj which shows that am is also a valid candidate for bj so a better move is to do a1 for bi (as it reduces the cost)

»
5 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

waw , Mate, D really gave me a proper thrashing

DAMN , although C is shit about D lol

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

Who agrees with me that B is harder than C and D?

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

Bro why does that G solution look so cracked, like how would you even come up with that.

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

B was cool :)

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

guys why didnt my score change????????

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

D and E are great, almost among the best problems I've encountered on this platform!

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

B is such a cool problem

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

Could solve 3 in this div1+2 as well

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

Did anyone solve D with DFA? It was nice building a DFA to solve an easy problem that could be solved with simpler observations. :V

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

Does anyone have a simpler explanation for E? I didn't understand what the editorial means by "cycles of a".

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

    same that statement was not obvious at all heres a explaination/proof

    Every permutation can be broken into disjoint "cycles". If you think of the permutation like a functions that maps (1-indexed) $$$i$$$ to $$$a_i$$$, then if you apply the permutation to itself, elements of each cycle will trade places with eachother.

    For example the permutation 2 1 6 3 5 4 can be broken into the cycles (1, 2) (3 4 6) and (5) because 1 maps to 2 and 2 maps to 1, 5 maps to 5, etc.

    The problem says if permutations $$$A$$$ and $$$B$$$ commute, than $$$A(B(i)) = B(A(i))$$$ for all $$$i$$$. if some element $$$j$$$ is in a cycle of length $$$n$$$ in $$$A$$$ then

    $$$A^n(j) = j$$$
    $$$B(A^n(j)) = B(j)$$$
    $$$B(j) = A(B(A^{n-1}(j)) = A^2(B(A^{n-2}(j)) = \dots = A^n(B(j))$$$

    $. therefore if $$$j$$$ is in a cycle of length n, then $$$B_j$$$ is also in a cycle of length n

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

For problem B, Can anyone please explain why each a[i] should be increased to smallest b[j] greater than a[i] ? After a lot of try, still this couldn't make sense to me.

»
5 месяцев назад, скрыть # |
 
Проголосовать: нравится +50 Проголосовать: не нравится

Thanks for the contest! In case it's helpful to others, I thought I'd write down some thoughts on my solution to G and its motivation.

A natural first strategy to attempt is to write down the array $$$a$$$, then write down some other numbers that can be used alongside the GCD operation to decode it. One problem with any strategy of this shape, though, comes from handling inputs consisting of large primes. If the array $$$a$$$ consists of $$$n$$$ large primes, then each of these primes must appear twice in $$$b$$$ for it to be a possible output of the GCD operation, so for such an input, $$$b$$$ would require at least $$$2n$$$ elements, which is infeasible.

This indicates that rather than writing down $$$a$$$ itself, we'll need to encode its elements in some more convenient way, then decode them later. That motivates thinking about what numbers are easy to identify in $$$b$$$ using the provided GCD elements. One natural idea here is that if we fix an element of $$$b$$$ to be the largest power of some prime $$$p$$$ less than $$$10^6$$$, we can take the GCD of any other element of $$$b$$$ with this one to count the times $$$p$$$ appears in its prime factorization. So, if we use powers of the 150 smallest primes as the 'spare' elements of $$$b$$$, we can use them to compute the exact values of all other elements of $$$b$$$, provided those elements don't have any prime factors outside of these 150 smallest primes.

By writing a brute force, we can find that there are just over $$$3 \cdot 10^5$$$ numbers up to $$$10^6$$$ that have sufficiently small prime factors and can thus be identified exactly if we put them in $$$b$$$. Say the exact count of such values is $$$k$$$. By writing down a map from these $$$k$$$ values to the first $$$k$$$ nonnegative integers, we can imagine that instead of using the GCD queries described in the problem, we're allowed to write down $$$\frac{10n}{9}$$$ values up to $$$k$$$ in $$$b$$$, and the second player receives those exact numbers and needs to restore $$$a$$$.

A reasonable starting point from here is to write down $$$a_i \bmod k$$$ for all $$$i$$$. Then, for every nine elements of $$$a$$$, we can add one extra element to $$$b$$$, and we need to use this element to restore the values of $$$\left\lfloor \frac{a_i}{k} \right\rfloor.$$$ But given $$$k \approx 3 \cdot 10^5$$$, this quotient has to be between $$$0$$$ and $$$3$$$, so there are $$$4^9$$$ possible sequences of quotients for a series of nine elements of $$$a$$$. Since $$$4^9 \lt k$$$, we can encode all nine of these quotients in a single element of $$$b$$$, e.g. by writing down a nine-digit number in base four. This is enough to solve the reduced problem, so we're done!

A mildly amusing aside: I was able to overkill F using segment tree beats (the first time I've actually used segtree beats to implement a problem), which saved me from thinking harder about how to use prefix minima/maxima to optimize the DP transitions :)

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

    I have another idea:

    We will encode $$$9$$$ consecutive numbers in the array $$$a$$$ to $$$10$$$ consecutive numbers in the array $$$b$$$.

    Let $$$base = 10^6 + 1$$$, and define $$$c_i = a_i * base^0 + a_{i + 1} * base^1 + ... + a_{i + 8} * base^8$$$ and we can change every $$$c_i$$$ $$$(i = 9 * x + 1$$$, there are $$$\lceil n/9 \rceil$$$ such $$$c_i)$$$ to other form, here I chose base $$$252000$$$ (we need a base of at least $$$\sqrt[10]{base^9} \approx 251189$$$ so it fits in $$$10$$$ digits).

    I chose $$$252000$$$ representatives of the form $$$2^x * 3^y * p_1 * p_2 * ...$$$ (I tried $$$2^x * p_1 * p_2 * ...$$$ and $$$p_1 * p_2 * ...$$$ but they don't have enough numbers less than $$$10^6$$$ to represent base $$$252000$$$) with $$$p_i$$$s are the first $$$140$$$ primes greater than $$$3$$$ and they have to be pairwise distinct. I'm pretty sure $$$140$$$ is somewhat large, it can be reduced further but it's not necessary because we only used $$$k = \lceil 10n/9 \rceil + 142$$$.

    We transformed a 9-digit number in base $$$10^6 + 1$$$ to a 10-digit number in base $$$252000$$$, Quack can just get the array $$$b$$$ in $$$\lceil 10n/9 \rceil * 140$$$ queries and decode to $$$a$$$ easily.

    I almost got that during the contest, but my base conversion code was stupidly bugged :( looking forward to see more interactive/communication problems soon.

    Implementation: 379431426

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

the prove of greedy problem on codeforces is terrible

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

Nice problems

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

Is there a typo in the tutorial for B? It isn’t necessarily true that a_m <= a_1, right?

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

Can anyone explain 2237C plz

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

Hi in c if we remove constraint of adjacent and swap any two position according to rule. can anyone suggest the way to the modified problem.

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

Rating problem D at 1500 is insane i guess, man that problem is tough.

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

d why the number of odd substrings for aletranting string is ⌊y−1/2] ?))

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

Problem I is a really great problem! The DP part is super detail-oriented. Fully digesting it really puts your understanding and implementation skills to the test.