AksLolCoding's blog

By AksLolCoding, 7 months ago, In English

Thanks to everyone who participated in this round! I hope you enjoyed the contest.

Rate the contest!
Rate the difficulty!

2200A - Eating Game

Rate the problem!
Tutorial
Code (C++)

2200B - Deletion Sort

Rate the problem!
Tutorial
Code (C++)

2200C - Specialty String

Rate the problem!
Hint
Tutorial
Code 1 (C++)
Code 2 (C++)

2200D - Portal

Rate the problem!
Hint 1
Hint 2
Hint 3
Tutorial
Code (C++)

2200E - Divisive Battle

Rate the problem!
Hint 1
Hint 2
Hint 3
Tutorial
Code (C++)

2200F - Mooclear Reactor 2

Rate the problem!
Hint 1
Hint 2
Tutorial
Code (C++)

2200G - Operation Permutation

Rate the problem!
Hint 1
Hint 2
Hint 3
Tutorial
Code (C++)
Bonus from Proof_by_QED

2200H - Six Seven

Rate the problem!
Hint 1
Hint 2
Hint 3
Hint 4
Tutorial
Code (C++)
  • Vote: I like it
  • +103
  • Vote: I do not like it

»
7 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

Great Problemset and fasttt editorial, loved D and E. AksLolCoding orz orz orz orz

»
7 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

Solution to G bonus

Spoiler
  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Can you explain what is S in terms of probability and why we multiply everything by 1/(m+1)

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      We are trying to calculate the expected value (EV) of the final value of the expression. To do this, by linearity of expectation, we can calculate the expected value of each additive term separately and sum them all to obtain the final answer.

      At the end of an arbitrary expression, an additive term $$$y$$$ will have the form $$$y \cdot X$$$, where $$$X$$$ is the product of all multiplicative terms to the right of $$$y$$$. There may be many possible values for $$$X$$$, but only its expected value matters to us.

      Let $$$S$$$ denote $$$\mathbb{E}[X]$$$, the expected value of $$$X$$$. The contribution to the answer for each additive term $$$y$$$ is, therefore, $$$S.y$$$. We now compute $$$S$$$.

      Again, by linearity of expectation (with a small twist), we have: $$$ S = \sum_{k=0}^{m} \Pr(\text{there are } k \text{ multiplicative terms to the right of } y) \cdot \mathbb{E}[\text{product if there are } k \text{ multiplicative terms to the right of } y]. $$$

      Each probability term is $$$\dfrac{1}{m+1}$$$ due to randomness, and each expected product term corresponds to the $$$\text{dp}/\text{choose}$$$ component.

      That's how the editorial finds $$$S = \frac{1}{m + 1} \sum_{k = 0}^{m} dp[m][k]/ \binom{m}{k} $$$

      If you, as I did until yesterday, struggle with comprehending Expected Values and it's manipulations that were used, i recommend you watch Errichto 's lecture on YouTube

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    So this solution requires 3 mod NTT?

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    This is be a valid solution for MOD=998244353 right?? is there a method to perform accurate polynomial Multiplication for MOD=1e9+7?? (FFT gave WA)

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

My first contest and I could actually solve smtg:)

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

Great contest! Loved the C and D problems. Can F be solved using knapsack algorithm? I am just learning DP algorithms and thought that the problem is similar to knapsack, correct me if I am wrong.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yes I think you can use DP here (knapsack one) but the issue is that it will TLE and MLE both,It is O(n^2) and since constraint are 2*10^5, 2 state dp would also fail, u can optimize this to 1 state DP array so MLE can be cleared but TLE cant be helped i guess.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Let dp[i]=max answer if we select pairs such that the min y is equal to i.

      Then answer for dp[i] can be calculated by using a priority queue (I'm not stating my implementation here, but basically for dp[i] I'm finding the max sum of x values for pairs of type (x,y) with y>=i)

      Then the problem says we have to find the answer for each pair in 'b' if we had that pair. So I consider 2 cases:

      1) we have the pair, but we don't use it: Then answer is simply max(dp[i]) as nothing changes.

      2) We may use it: Let's say the pair is (X,Y). If I include this pair in my array a, then dp[i] for i>Y won't change. But dp[i] for i<=Y may change. Because,

      (i) it may be possible that the min values out of the selected i values (for some dp[i]) may be less than X

      (ii) it may be possible that dp[i] was calculated with us having selected less than i values, which means there's room for more elements to add.

      So I just maintain some values in order to find the max for each (X,Y).

      But it gives WA on TC2, so I'm wrong somewhere. But idk where, it seems alright to me.

»
7 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

In C, I thought that matching characters will have different effect based on positions only to realise after the contest that it doesn't, cool problems

»
7 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

It was my first contest and it was actually good, I solved 2

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

Thank you for the editorial! Isn't code 1 for C incorrect?

What is wrong
»
7 months ago, hide # |
Rev. 2  
Vote: I like it +4 Vote: I do not like it

O(n) solution for C

As explained in the editorial, it is always optimal to delete a pair when you find one. You can avoid looping through the string multiple times by mantaining a stack with all currently undeleted characters. Loop through characters in the string from start to end. When you encounter character $$$c$$$ in the string, if it matches the top element of the stack, $$$t$$$, then $$$c$$$ and $$$t$$$ will eventually become adjacent after a bunch of deletions, so remove $$$t$$$ from the stack. Otherwise, add $$$c$$$ to the stack. If the stack is empty after looping through the string, it's possible to turn the string into stars.

int n;
string s;
cin >> n >> s;
stack<char> st;
for (char c : s) {
	if (!st.empty() && st.top() == c)
		st.pop();
	else
		st.push(c);
}
cout << (st.empty() ? "YES\n" : "NO\n");
  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Isn't answer is YES for the case "aaabb" like first select i=0 and j=2 set all a's to * then select i=3 and j=4 and set all b's to * so it is possible to convert string s to all *

    but your as well as editorial code gives answer as NO

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      No you can't choose $$$i=0$$$ and $$$j=0$$$ at the start because the question says $$$i, j$$$ must satisfy $$$s_k = *$$$ for all $$$i \lt k \lt j$$$. You might have misread the question to say that you set $$$s_k = *$$$ for all $$$i \lt k \lt j$$$

      The question is asking about deleting pairs anyways, so it's always impossible when $$$n$$$ is odd

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

AksLolCoding In tutorial of E, shouldn't it be "If bi is non-decreasing, then Bob will win."?

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

i felt E was easier than D probably because D involved heavy implementation or rather i overcomplicated its implementation :) but it was a great contest

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Nice problems!

»
7 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

For G bonus: I suppose $$$O(n^{\log_2(3)})$$$ can pass with some minor optimizations.

I have an idea for an $$$o(n\log{n})$$$ solution for F, which is just improvising $$$O(n\log{n})$$$ parts with $$$o(n\log{n})$$$ parts, e.g. replacing standard sorting with radix sorting, and using e.g. a vEB tree to manage the set. Even though I'm not sure it'll run better since $$$O(n\log(n))$$$ with a simple heap is already 100ms.

F was pretty good, not some boring DP like the last few rounds, wasn't brutal but hard enough for me to think.

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

Great ProblemSet

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

The problems are really excellent. I will compete Div.3 next time.

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

bruh in B i got hyperfixated on max and min values to find some pattern from them that i didnt think any element would work :(( solved c in 5 mins remained stuck at B for 45 mins. Good contest

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

I got stuck at last one. I KNEW I SHOULDVE DIVIDED THE x+k IM BADDDDD

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

Question D is really interesting!

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

Really loved it. Great questions,lots for me to learn.Thank you for all who contributed to this.

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

Great contest

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

AksLolCoding for editorial of problem F shouldn't it be a MIN heap instead considering we'll remove the element with the least energy from the heap

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

The problem E is so hard

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

For problem 2, I guess the answer should be 2 for every testcases except for an empty list because what you can do is just Sort the array and then reverse it.

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

Damn, couldn't figure out D on my own.

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

A little bit different solution for Task E: -

I used a simulation-based thought process, focusing on the explicit sequences each player tries to construct: -

We know that: -

  • Alice wants to make the array unsorted. Her goal is to create a state where $$$A_i \gt A_j$$$ for some $$$i \lt j$$$.

  • Bob wants to keep the array sorted. His goal is the exact opposite, ensuring $$$A_i \le A_{i+1}$$$ for all valid $$$i$$$.

  • Because both players play optimally, for a composite number $$$C$$$ with prime factors as $$$p_1 \le p_2 \le \dots \le p_k$$$ is changed in a specific arrangement, by alternately distributing the prime factors into a left and right partition (and reversing the right), the split naturally $$$S$$$ is increasing first, then decreasing. Mathematically, this is like a bitonic sequence that looks like this: —

$$$S = (p_2, p_4, \dots, p_{\text{peak}}, \dots, p_3, p_1)$$$

Combining these observations, we can construct the final modified sequence by replacing every composite number with their respective expanded sequences.

Once we create this fully expanded sequence, our final check is very simple: If the final modified sequence is non-decreasing, Bob wins. Otherwise, Alice wins. There's also a base condition that if the initial sequence is non-decreasing in the first place, then Bob wins.

I hope this helps! :)

Submission Link

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    But for every element alice can't start first then how is this possible for every element. S=(p2,p4,…,ppeak,…,p3,p1)

    for instance: 16 10 25 if alice choose 16 first, next bob choose 10. So, Definitely alice need to choose 10 and split like 5*2, then only alice can win.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      you’re correct about the part that alice must choose to split 10, and that’s exactly why she would never start with 16 as it’s the sub-optimal choice, simply because 16’s a perfect power of 2, similar to how 25 is a perfect power of 5!

      simply put, the simulation can be seen as finding a particular composite number, whose factorisation can be made non-decreasing, since one such number is enough to guarantee alice’s victory, the rest of the simulation isn’t actually necessary.

      moreover, it doesn’t make our answer incorrect at any point simply because of the fact that if there exists a winning move for alice, she can do that move first and then play the entire game with bob just for the sake of it (simulation), in case there is no winning move for her then again the simulation can’t generate a winning position and hence bob wins!

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

For problem D, consider this input

1 11 2 8 2 1 5 3 6 5 3 5 4 6 3

The code in the tutorial gives 2 1 3 6 5 3 5 5 4 6 3 However, I think the actual output should be 2 1 3 5 5 3 6 5 4 6 3 Can someone clarify if I'm thinking correctly? Nvm, the input is invalid. Sorry in advance

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

wait this is actually a really good editorial. AksLolCoding orz

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

I was doing the contest and I had a question about problem C. In the solution logic, we delete characters in pairs, but if we have a case like "llml", what happens? In theory, the answer should be YES, but when running the algorithm it gives NO, someone can explain to me?

  • »
    »
    7 months ago, hide # ^ |
    Rev. 4  
    Vote: I like it 0 Vote: I do not like it

    The answer is no because when there is no more movements all characters should have be changed to * (eliminated), in your example, the only two scenarios are the following:

    1. llml -> **ml -> game ends, not all characters are * -> AksLolCoding lost
    2. llml -> *lm* -> game ends, not all characters are * -> AksLolCoding lost
»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

364648115 submission, how and why would someone ever write Check is alaready decreasing in such a nice way. huge cheating AI sus https://codeforces.me/contest/2200/submission/364648115 this young bright mind solved B and C but was too smart to do a stupid q like A, cudnt do wow had 3 WA on test case 1?????? https://codeforces.me/submissions/Zero-zaber/contest/2200

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

Really liked G problem! Such a great one, sadly got accepted only after round:( I bet for better time complexity FFT might be helpful

  • »
    »
    7 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    You can even use the exp-log trick for an $$$O(n \log(n))$$$ solution. Actually E has the time complexity of $$$O(n \log^2(V))$$$. I forgot that the number $$$x$$$ only needed a prime base and not being a prime itself.

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

isn't A is B and B is A for problem D code ? please correct me if wrong .

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

Guys, support our flash mob and go to the "банда мопсоу" organization, and also put this picture as your avatar. Thanks to everyone who took part

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +4 Vote: I do not like it
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for the problem C: lets assume that our string is special and indexes are 1,2,3,...,n. Then we can pair these indexes such that for any pair (i,j) that they selected in some operation. (which means s[i]=s[j]). Then for any pair (a,b) and (c,d) its impossible to be like a<c<b<d. That explains why the order of the operation does not matter since our string should be concatenation of some even length palindrome strings.

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

Can someone explain to me why are we iterating over m (mod 42) ? I don't get the intuition behind it.

»
6 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it
Even Palindrome like solution for C
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When will these questions be rated ?

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

In H, why are you including those numbers in the next recursion depth, which are already special at this level? Does this not fail to minimize the number of operations?

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

A Slight Different Approach for Problem C using recursion and string size

bool func(string s)
{
 
    ll n = s.length();
    if (n == 0) return true;
    f1(i, 1, n)
    {
        if (s[i] == s[i - 1]) {
            s[i - 1] = s[i] = '*';
        }
    }
    string temp = "";
    f1(i, 0, n)
    {
        if (s[i] != '*') temp.pb(s[i]);
    }
    if (temp.size() == n) return false;
 
    return func(temp);
 
}
void solve() {
    ll n; cin >> n;
    string s; cin >> s;
    if (n & 1)
    {
        cout << "NO";
        return;
    }
    if (func(s))cout << "YES";
    else cout << "NO";
 
 
 
}

369425890

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

Hi Codeforces! Problem E 2200E - Divisive Battle. Please do check out this O(N) solution, 369918055, of mine which uses pre-computation by adding some variation in Sieve of Eratosthenes. Feedback is highly appreciated!

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

In the solve of problem D, the line "while (it != a.end() && *it < m) it++;" should be revised. It should be "*it <= m" instead of "*it < m".

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

AksLolCoding thankyou for D & E