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

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

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++)
Разбор задач Codeforces Round 1084 (Div. 3)
  • Проголосовать: нравится
  • +103
  • Проголосовать: не нравится

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

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

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

Solution to G bonus

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

My first contest and I could actually solve smtg:)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Nice problems!

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

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

Great ProblemSet

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

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

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

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

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

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

Question D is really interesting!

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

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

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

Great contest

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

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

The problem E is so hard

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

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

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

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

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

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

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

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

wait this is actually a really good editorial. AksLolCoding orz

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

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

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

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

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

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

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

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

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

»
6 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
Even Palindrome like solution for C
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

When will these questions be rated ?

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

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

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

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

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

AksLolCoding thankyou for D & E