NetSpeed1's blog

By NetSpeed1, 4 weeks ago, In English

2048A - Kevin and Combination Lock

Author: Little09

Hint 1
Tutorial

2048B - Kevin and Permutation

Author: NetSpeed1

Hint 1
Tutorial

2048C - Kevin and Binary Strings

Author: Little09

Hint 1
Hint 2
Hint 3
Tutorial

2048D - Kevin and Competition Memories

Author: cmk666

Hint 1
Hint 2
Hint 3
Tutorial

2048E - Kevin and Bipartite Graph

Author: Little09

Hint 1
Tutorial

2048F - Kevin and Math Class

Author: NetSpeed1

Hint 1
Hint 2
Tutorial

2048G - Kevin and Matrices

Author: cmk666

Hint 1
Hint 2
Hint 3
Hint 4
Tutorial

2048H - Kevin and Strange Operation

Author: JoesSR

Hint 1
Hint 2
Hint 3
Tutorial

2048I1 - Kevin and Puzzle (Easy Version)

Author: Little09

Hint 1
Tutorial

2048I2 - Kevin and Puzzle (Hard Version)

Author: Little09

Hint 1
Hint 2
Hint 3
Hint 4
Tutorial
  • Vote: I like it
  • +118
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

first

I was one $$$=$$$ sign off from getting $$$E$$$ lol

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

    Haha me too. I wrote > 2*n instead of >= 2*n lol. Now first time losing rating

»
4 weeks ago, # |
  Vote: I like it +45 Vote: I do not like it

I think the $$$O(n)$$$ solution for C is quite interesting. Why not split it into a C2?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I agree

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it -9 Vote: I do not like it

      that would have been still better than E problem.

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

        do you hate problem E? lets hug if so

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I was trying to solve C by explicitly taking XOR from numbers (i.e. binary transformed into decimal) and obviously ran out of memory. And then I came to the $$$O(n)$$$ solution.

    (edited)

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

      bro skipped a step from taking the xor of numbers of 5000 digits to finding the optimal solution

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Even I solved C in O(n). Was able to prove my hypothesis on working with first 0 and first 1 after first 0.

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        could you explain the logic behind the O(n) solution i don't get the editorial

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      can you explain the O(n) solution

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Lol I directly coded the O(n) solution :D Slight observation but I was able to get that correct in one go.

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I saw that the bounds allow for $$$O(N^2)$$$, but since I quickly saw greedy should also work, I was too lazy to think about index handling for the $$$O(N^2)$$$ solution, so I just went and solved it $$$O(N)$$$. :)

»
4 weeks ago, # |
  Vote: I like it +2 Vote: I do not like it

First time ever i solve 5 problems in a div2, i think D is very cool, and i kinda guessed E but good contest overall

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

great contest and tutorial :)

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

Can anyone explain why my D Solution is too slow?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    O(m^2) solution is going to give you TLE as m<=3e5

»
4 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

great contest tho I find it wired that F requires such complex data structure (probably it isn't wired and I just lack experience)

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's not complicated structure for F.

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it +31 Vote: I do not like it

    Honestly a min Cartesian Tree is just a fancy way of refering to the classic problem of finding for each element its first lower neighbours on the left/right.

    Now you can say that each element is the node corresponding to an interval, and all you need to add is to compute the two childs in the tree (which corresponds to the interval splitted by the minimum value), which requires a bit of thinking but no complicated code.

    Finally to manage the DP in the tree you can do simply dfs using the indices of intervals and never explicitly construct the tree, like you would do in a divide and conquer approach.

    All in all it might be a complex idea but it can be implemented easily (you can check my submission if you'd like (which is $$$O(nlog^2)$$$ should you wonder))

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

Special Thanks to cmk666 for the nice problem 2048D - Kevin and Competition Memories

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

one more div2 contest where i can't solve more than 3 questions.

how should i practice to solve question D in div 2 contests? thanks in advance

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

Anyone tried solving E with below approach.

Each edge can be represented as ordered pair ( i , j ) . where 'i' belongs to left side, and 'j' belongs to right side.

Now, we have total of 2 * n * m such ordered pairs. each of these edge can be actually convert into a vertex. since our graph is bipartite, after we travel one of our edge, next edge direction will be opposite ( if we travel current edge from left to right, next edge we must travel right to left )

=> if I am going from (i,j1) to (i,j2) , i will try to give available color to (i,j2) and then I will keep 'j2' constant and try to find some valid 'i' which is not yet colored and try to color it.

Now start DFS from (1,1) , and if its odd iteration of the we will go from left to right, if it is even iteration, we will go from right to left.

When we go from left to right , we will keep 'i' constant and loop over all the 'j' in the ordered pair ( i , j ) .

When we go from right to left, we will keep 'j' constant and loop over all the 'i'.

We will try to basically color this graph of 2 * n * m vertices,,, with 'n' colors. I tried this approach, but don't know, why does it fail ?

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    If n < m your solution does not find the answer. While answer exists in some cases. Consider n = 3, m = 4.

    Answer for n = 3, m = 4
    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I know, my above logic is flawed.

      Then I had thought of doing BFS instead of DFS ( which was also flawed )

      Then I thought of doing color-wise bfs (pass specific color to the bfs, and try to paint as many edges you can with the given color without generating the cycle. This approach itself is O ( n ) * O ( 2 * n * m ) So, I didn't bother implementing it.

      I wish, we could reduce it to some sort of graph coloring problem, than just guess-work.

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

        Any greedy approach to general graph coloring problem will be doomed to fail. Since general graph coloring problem is NP-Complete, you can not solve it in polynomial time, unless P = NP. In this type of problems most probably you have to build certain construction for specific type of graph. In this case we need to use the fact that complete bipartite graph is given.

        In my approach I did the following. Think about each color separately, and try to use certain edges for this color such that the graph induced by these edges does not contain a cycle, i.e. is a forest. Then you try to cover the whole set of edges using these forests for each color.

        • »
          »
          »
          »
          »
          4 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          thank you for detailed explanations. Wish you GM soon.

»
4 weeks ago, # |
  Vote: I like it +14 Vote: I do not like it

E made me sad.

»
4 weeks ago, # |
  Vote: I like it +9 Vote: I do not like it

G is a nice one! ❤️

»
4 weeks ago, # |
  Vote: I like it +15 Vote: I do not like it

For F, the constraints don't cut the $$$n \cdot \log^2(a)$$$ solution, but also make it harder for people who are careful.

I spent extra time to optimize out a $$$\log(a)$$$ factor just like the editorial because $$$n \cdot \log^2(a) \approx 8 \cdot 10^8$$$.

If instead the time limit was greater or $$$a = 10^9 \implies n \cdot \log^2(a) \approx 2 \cdot 10^8$$$, I would definitely go for this solution and not waste time. Since I optimized, I failed to finish F by a few minutes.

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

    I didn’t pass with log^2 so it’s kinda a gamble…

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

Was curious about F's solution and heard for the first time about min cartesian tree!! Anyone have any good resources to learn more about it?

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

Why is this code for D failing?


int n, m; cin >> n >> m; int me; cin >> me; vector<int>participants, problems, solved; // only participants with rating greater than mine matter for (int i = 0; i + 1 < n; i++){ int num; cin >> num; if (num > me) participants.push_back(num); } // same thing for problems for (int i = 0; i < m; i++){ int num; cin >> num; if (num > me) problems.push_back(num); } sort(participants.begin(), participants.end()); sort(problems.begin(), problems.end()); // computing how many people solve each problem for (int problem : problems){ int first = lower_bound(participants.begin(), participants.end(), problem) - participants.begin(); solved.push_back(participants.size() - first); } sort(solved.begin(), solved.end()); for (int k = 1; k <= m; k++){ int ans = 0; for (int i = k; i <= solved.size(); i += k) ans += solved[i - 1] + 1; cout << ans << " \n"[k == m]; }
  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I had a similar implementation which worked : 297364236 I dont think you can ignore problems with lower difficulty than Kevin's skill since you can use them to "pad" contests

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

      bro im gonna be honest i dont even know what am im doing, could you explain what the greedy algorithm the editorial describes is doing ?

      • »
        »
        »
        »
        4 weeks ago, # ^ |
        Rev. 2   Vote: I like it +3 Vote: I do not like it

        Consider a problem which has difficulty X such that X > Kevin's skill. Then if the number of people who can solve this problem are Y, this means that if you include this problem in a contest, at least Y people will be ahead of Kevin since Kevin can't solve it.

        If the difficulty X is equal to or less than Kevin's skill, then no one will be able to get ahead of Kevin using only this problem, in which case the number of people ahead of Kevin is 0. So, for each problem P[i] you can calculate how many people can potentially get ahead of Kevin using only P[i] (say we call this value Ahead[i]).

        Now you need to create K groups. Kevin's final ranking in a group will be max(all Ahead[i] values in the group) + 1. For example If the group has Ahead values 0 1 4, that means everyone solves the first problem, the second problem is solved by one person who is not Kevin and the third problem is solved by 4 people but not Kevin. This means that a total of 4 people are ahead of Kevin, giving Kevin 5th rank (Note that the person who solves the second problem is also among the people who solve the third problem, which is why we take max(Ahead[i])). The final answer is the sum of ranks across all groups.

        Now in order to minimize the sum, you must minimize the max(Ahead[i]) in each group which you can do by greedily assigning K values with lowest Ahead[i] in the first group, next K lowest in next group and so on. So if Ahead array is 0 1 3 5 and K = 2, we make groups (0, 1) and (3, 5). The sum of ranks would be max(0,1) + 1 + max(3, 5) + 1 = 2 + 6 = 8

        I hope this didn't confuse you even more lol

    • »
      »
      »
      4 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Wait I think I got it. When constructing the answer we need to take the k problems the least amount of people solved. So we get the k first problems after padding them out. Is this it? I still don't know how the solution doesn't raise TLE though

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        For each K from 1 to m, you start from (K-1)th index and increment by K as long as the index < m. So for K = 1, there are m operations. For K = 2, m/2 operations and so on which results in MLog(M) complexity. Hence no TLE

        • »
          »
          »
          »
          »
          4 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          yeah turns out we're doing m * (1/1 + 1/2 + 1/3 + 1/4 + ... + 1 / m) operations which is the harmonic series sum thing the editorial mentions, which is log(n) for some reason so ok nice

»
4 weeks ago, # |
  Vote: I like it +74 Vote: I do not like it

For E, I found this paper which solves a slightly more general problem of coloring a complete bipartite graph into the minimum number of colors such that each color is a forest.

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

Can someone please help me out where I am going wrong with C: my submission

I get that the first substring will be the entire string, and the second substring will be of the length = length of complete string — position of first 0 from left. But since we only have to find out which such substring gives the maximum XOR, I take a different parameter called 'ans' in my solution and I claim that the substring which gives the higher 'ans' will also give the higher XOR value.

Here is how I am constructing 'ans': I am comparing the portion of two strings which is to be XOR'ed. Starting from the most significant bit, if the corresponding bit in both the strings are 0 and 1 respectively, I am incrementing ans by a larger value (and decrementing if the bits are 1 and 1 respectively since that will decrease XOR value). As I move from left to right, The value with which I increment/decrement ans decreases (since the right bits will have less contribution to the XOR value than the left bits). The substring which gives the maximum 'ans' value will also give me the maximum XOR value. But I am getting wrong answer on test case 2 itself and I am unable to figure out where I am going wrong! Please help

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it -9 Vote: I do not like it

    Maybe my implementation can help you:


    string s; int n; cin >> s; n = s.size(); bool hasZero = false; for (int i = 0; i < n; i++) if (s[i] == '0') { hasZero = true; break; } if (!hasZero) { cout << 1 << " " << n << " " << 1 << " " << 1 << endl; return; } int first_zero = 0; for (int i = 0; i < n; i++) if (s[i] == '0') { first_zero = i; break; } int best_l = 0; int sz = n - first_zero; for (int l = 0; l <= n - sz; l++) for (int i = 0; i < sz; i++) { if (s[first_zero + i] == '1') { // If at this position of the string we have a 1 if (s[l + i] == '1' && s[best_l + i] == '0') // If the current substring has a 1 and my current answer has a 0, the current substring is worse and should not be processed break; if (s[l + i] == '0' && s[best_l + i] == '1') { // If the current substring has a 0 and the current answer has a 1 I found a better answer best_l = l; break; } } else { // if the original string has a '0' if (s[l + i] == '0' && s[best_l + i] == '1') // if the current substring has a 0 and the answer has 1 then this is worse and should not be processed break; if (s[l + i] == '1' && s[best_l + i] == '0') { // if the current substring has a 1 and the answer has a 0 i found a better answer best_l = l; break; } } } cout << 1 << " " << n << " " << best_l + 1 << " " << best_l + sz << endl;
    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks for your code, I completely understood it. However, I still haven't understood what is wrong in my implementation.

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I think your ans logic is flawed, say you have two candidates for strings, the first one has a better most significant bit and the other one has a worse most significant bit but every other bit is better in the second one. Maybe the way your ans is incremented makes the sum of the second one better than the first one if that makes sense

        • »
          »
          »
          »
          »
          4 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Ahh now I get it! I have been trying to figure out a flaw in my logic since the last 4 hours, only to find out it was this trivial :')

          Thank you very much for pointing this out!

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

      Please do not post entire solutions in the comments. Makes it very noisy to scroll through the comments. Paste submission links.instead.

»
4 weeks ago, # |
  Vote: I like it +21 Vote: I do not like it

I hate the fact, that I was debugging F for 40 minutes, because I was getting RTEs on test 3. There was some stupid stack overflow; the recursion was returning a big static object (488 bytes), and after changing it to return an 8 byte pointer, it started working; however, my memory usage was under 350MB, so it should have passed initially.

  • »
    »
    4 weeks ago, # ^ |
    Rev. 3   Vote: I like it +34 Vote: I do not like it

    Edit: Codeforces DOES pass -Wl,--stack=268435456 to the linker, however it means the stack limit is always 256MiB regardless of the problem's memory limit. This is totally unreasonable.


    Original comment:

    It is because codeforces's judging environment is Windows, and it seems that they don't pass -Wl,--stask=xxx to the linker, which leads to a stack limit which is smaller than memory limit. I hope MikeMirzayanov could fix it, as more than one contestant faced it during contest time.

»
4 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

Good contest,make me promote to IM :)

»
4 weeks ago, # |
  Vote: I like it +23 Vote: I do not like it

Little09 Can you elaborate on the $$$O(n\log^2n)$$$ solution for I2? Idk what block convolution is.

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

    There is a solution of complexity $$$O(n\sqrt{\frac{n\log n}{\omega}})$$$. The general idea is to divide the sequence into chunks for every $$$B$$$ positions, and for each $$$l+r$$$ value find the $$$r$$$ that minimally satisfies the condition. If $$$l,r$$$ belongs to different blocks, enumerating the blocks of $$$r$$$ and then convolving this block with the prefixes tells us which $$$l+r$$$ occur, and then finding the smallest $$$r$$$ within the block. The case where $$$l,r$$$ belongs to the same block is easily solved. Finally, the bitset optimization is performed to obtain a complexity of $$$O(\frac{n^2}B\log n+\frac{nB}{\omega})$$$.

    About $$$O(n\log ^2n)$$$ solution, it comes from JoesSR and it is more difficult and maybe I will add in the Editorial in a few days.

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

CONGRATULATIONS! my friend chenlinxuan0226 reached CM after this contest!

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

"In fact, this is easy to construct"

Even after reading more than 5 times, above statement still hurts my soul.

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

    I think it will be easy, if you make construction this way:

    Our answer should satisfy the following property, if we fix two rows i.e., the nodes on the left side, there should not be greater than two columns of same colours.

    Like this case where there are two columns of (1, 1) which forms cycle for a pair of nodes on left. So, it won't work.

    1....1.....2

    3....3.....4

    1....1.....3

    By trying out small cases and making construction based on this would be easy.

    So, for (n, m = 2 * n — 1), you could always find a case, where there are no two columns of same colour for every possible pair of rows. And this also satisfies for all m <= 2 * n — 1 (Printing the array till m columns).

    for n = 4

    1 1 1 1 2 3 4

    2 2 2 2 3 4 1

    3 3 3 3 4 1 2

    4 4 4 4 1 2 3

    1 2 3 4 1 1 1

    1 2 3 4 2 2 2

    1 2 3 4 3 3 3

    1 2 3 4 4 4 4

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

      Why Doesn't this case work for 2,4

        1. 1 2 1 2
        1. 2 1 1 2
        1. 1 2 2 1
        1. 2 1 2 1
      • »
        »
        »
        »
        4 weeks ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        There is a monochromatic cycle L1 — R1 — L3 — R4 — L4 — R2 — L2 — R3 — L1, where L and R are set of nodes on right and left respectively.

        I didn't think about a case like this while solving, but luckily the construction, I made didn't lead to these cycles.

        UPD: Still, here m >= 2 * n (Doesn't work anyway).

»
4 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

Why my stupid $$$\Theta(n\log^2 v)$$$ solution for F ran for just 827ms, can sb hack it or did it just run too fast because of constant factor? 297330202

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

got my first problem C !!!!

i somehow thought of the o(n) and not o(n^2) on C lol

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

Proof (for problem C) of why (1,n) is always one of the substring.

let leftmost '1' occurs at pth position(from right to left) no other substring can have (p+1)th position '1' hence can never exceed the xor of one pair created using (1,n) as one substring.

also 2^k> 2^(k-1)+ 2^(k-2)....... +2+1. so if you could get xor with all bits '1' and with length (p-1) it will still be smaller than which could be generated using (1,n) (pth position '1').

please correct me if i am wrong.

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

Can't we include visual explanation with images in editorial? then many more participants can upsolve the problems and can Improve, i usually find difficulty to understand the text solution.

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

Identity V?

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

Finally, after losing hope so many times. I can now understand "how to understand the problems". I may seem funny/absurd/weird to others, but I'm glad.

Also, it's a great contest. Registered for extra registration and able to understand questions. I almost got the C but missing a piece to complete. Way to go and learn. Hope for great learning !

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

I have a doubt in problem C, if the problem does not say that string starts with '1' does it will change the answer?

I yes how?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Well you always want one of the strings to be in the range of [the left most one,1]. So instead of solving on the entire string, you would first check the edge case of all 0s and then just solve the same thing on the substring from where the first 1 ocurrs

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

Can someone help me identify where I went wrong in this solution 297315319? I believe my solution has a time complexity of $$$O(n^2)$$$, yet I am experiencing a TLE for test case 21. Any assistance would be greatly appreciated.

How my code works
  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In the worst-case scenario, if the test case is 1, the length of s is 5000, and the string is "111...110", your code will execute approximately 5000 × 5000 × 2500 operations. This happens because the code compares the entire string with every suffix of the string. On average, the length of these suffixes is about 2500. I hope this explanation makes sense.

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

I had so much fun doing C, firstly I devised O(n^2) solution then I noticed I can use concept of MSB once again and voila got O(n) solution. Spent 1 hour on this though.

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

can anyone please tell me what is wrong in my solution of D ?297397178

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

Problem E's idea is same as AGC061 B. :/

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

I think my solution on C is O(n³) but somehow passed can you hack it?297271696

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

    I think it is O(N^2) ?

  • »
    »
    4 weeks ago, # ^ |
    Rev. 5   Vote: I like it +3 Vote: I do not like it

    Yes It's $$$\mathcal{O}(n^3)$$$

    because first loop runs in $$$\mathcal{O}(n)$$$

    Second loop running as follows :

    $$$(1)+(1+2)+(1+2+3)+..+(n-1+n-2+...+0)$$$
    $$$\displaystyle \sum_{i=0}^{n-1} \sum_{j=1}^i j = \sum_{i=0}^{n-1} \left(\frac{i(i+1)}{2} \right)$$$
    $$$\displaystyle \frac{1}{2} \left( \sum_{i=0}^{n-1} i^2+i \right)$$$
    $$$\displaystyle \frac{1}{2}\left(\frac{(n-1)(n)(2n-1)}{6}+\frac{(n-1)n}{2} \right)$$$
    $$$=\mathcal{O}(n^3)$$$

    Abito Sir you're lucky that you submitted with G++23 :holyfuck:

    297418046 G++23 AC 297417974 G++ 17 TLE

    btw It's indeed hackable (imo)

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

      I don't know a lot of math but still i can say that:

      i goes from : (n-1)--->0; j goes from : (i)---->0;

      overall the inner statements of second loop will run like :(n-1)+(n-2)+(n-3)+..+3+2+1 times.

      hence O(n^2).

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I've been trying to hack it but couldn't. djm03178 might be able to :)

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I think $$$5000$$$ 1's is the worst case for this solution but it runs in less than 1.7 seconds in custom invocation, so I doubt. The part that makes this $$$\mathcal{O}(n^3)$$$ is if (a>ans) and ans=a;, but the former is just one of the lightest operations (also a long prefix of the two strings should be matched to take a long time) and the latter can only be executed when we have more zeroes, which increases the number of skips at if (s[j]=='0') continue;.

        • »
          »
          »
          »
          »
          4 weeks ago, # ^ |
          Rev. 2   Vote: I like it -7 Vote: I do not like it

          When I ran the $$$5000$$$ 1's in G++ 17 It took about $$$5$$$ seconds .

          • It's already TLE'd with G++ 17.
          • »
            »
            »
            »
            »
            »
            4 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Yes, there has to be some kind of optimization in C++20 that does these operations much faster.

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

Is it only me who find it really difficult to understand Problem D tutorial?

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

Why is this submission get WA on #2? 297329851

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

I didn't enjoy this contest though the problems are not so bad.

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

Can someone explain why a greedy solution doesn't work for F.

Here I'm thinking to construct a Cartesian Tree, then starting from the root (which is the node with minimum value $$$b[i]$$$) just divide all elements in the range with $$$b[i]$$$ until $$$a[i]$$$ reaches $$$1$$$, then traversing down through the trees. It intuitively makes sense since the root node can only be divided by $$$b[i]$$$ so might as well divide the as large of a range possible. Then, recursively thinking, the children of those nodes can be divided with $$$b[j]$$$ which is greater than $$$b[i]$$$ thus better so we perform the same action until all $$$a$$$ is 1.

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For this case:

    3
    4 2 4
    3 2 3
    

    Using your solution, it would use 3 steps. Divide [1,3] by 2, [1,1] by 3, and [3, 3] by 3.

    However, it can be done in 2 steps. Divide [1,3] by 2 twice.

    Your solution's problem is that the program does not know when to stop using a certain $$$b[i]$$$. Just because $$$a[i] = 1$$$ doesn't mean that we stop using that $$$b[i]$$$ on the whole range.

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

can anyone explain prob e i am not unable to understand the editorial

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

Here's a different (?) breakdown of the main case for I2, at least for me it's easier to understand.

Assume we're in the RL case (i.e. $$$s = R \ldots L$$$). All values of $$$a_i$$$ then are in $$$[1, m]$$$. Let's consider where 1's are.

First, the entire array may be 1s anyhow. Add 1 to the answer for this case.

Otherwise, at most one (leftmost) L and at most one (rightmost) R may be 1. If both are 1, then every element of the array sees a 1, thus we can remove them both, decreasing all other values by 1. We should also remove all but one character among the leading Rs and trailing Ls (because all those are forced to be equal to $$$m$$$). Note that this case is impossible when the string looks like $$$RR \ldots LL$$$. Add the (say, recursively computed) answer for the resulting string.

If, say, only the leftmost L is 1, then the rightmost R is at least 2. Then the values for the trailing Ls must have something other than $$$m$$$. Looking at the rightmost such element, we conclude that it's a unique $$$m-1$$$ in the entire sequence. Then consider removing: 1) all leading Rs, 2) leftmost L, 3) characters corresponding to the the $$$m-1$$$ and all $$$m$$$s to the right of it. Basically, the sequence $$$a_i$$$ looks like $$$[m, m, \dots, m, 1, (\ldots), m - 1, \ldots, m]$$$, and none of $$$1, m - 1, m$$$ appear anywhere else. Every element in the central $$$(\ldots)$$$ part sees exactly two distinct values among $$$1, m - 1, m$$$, thus we obtain any such solution by solving the $$$(\ldots)$$$ and adding 2 to all $$$a_i$$$. However, the distinct values of $$$a_i$$$ for the $$$(\ldots)$$$ must fill a range $$$0, \ldots, x - 1$$$, thus when trimming border characters in $$$( \ldots)$$$ like before we can't encounter another RL case. This can checked with bitsets, and there are $$$O(n)$$$ situations to check.

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

D is an interesting problem.

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

Could anyone explain why the power of -1 is i+j in problem G?

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    Let's consider 1-D case, suppose the matrix size is $$$1 \times n$$$.

    Define the set with $$$Property_i$$$: those i-th position of the matrix get the maximum value K, the size is $$$K^{(n-1)}$$$

    Then the intersection of $$$Property_i$$$ and $$$Property_j$$$ size is: $$$K^{(n-2)}$$$

    So we can use inclusion-exclusion principle:

    The union of all $$$Property_i$$$ size is $$$\sum_{i=1}^{n} (-1)^{i-1} \tbinom{n}{r} K^{(n-i)}$$$

    When it comes to the 2-D case, I am a little confused about how the property of the set should be defined and what the intersection of two properties should look like.

    • »
      »
      »
      4 weeks ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      I had the same question and here is what I think the writer meant:

      Consider choosing just doing inclusion exclusion on $$$I$$$. You get a factor of $$$(-1)^{I+1}$$$. Then you have to do inclusion exclusion on $$$J$$$, there you get a factor of $$$(-1)^{J+1}$$$. You multiply then to get $$$(-1)^{I+J}$$$.

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

can someone please help me why am i getting a WA in D 297718482

first i sorted both the arrays

then if m%k!=0 i tried rejecting the problems which were just greater then that of kevin, for eg if remainder is two, i removed two problems just greater in rating than that of kevin's

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

I'm not understanding in Problem E, the fact "for any given color, there are at most 2n+m−1 edges", can anyone help me? Why is that true?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You can alternately connect the vertices on the left and right sides and you'll get a chain.Total vertices number is n*2+m,so the maximum edges is n*2+m-1.

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

Can Someone tell me in Problem C why this code work for this kind of input string 101111111111111111111111 .Code 298163280

»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain the $$$O(n \log n)$$$ solution for problem F? I only understand the $$$O(n \log^2 n)$$$ solution.

  • »
    »
    2 weeks ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    The DP function is $$$f_{i+j} = min(f_{i+j}, max(fl_i, fr_j))$$$. Assume that we start with $$$fl_0$$$ and $$$fr_0$$$ and, wlog, $$$fl_0 > fr_0$$$, we will never need to pair $$$fl_0$$$ with any $$$fr_j$$$ where $$$j > 0$$$ because that won't give us a more optimal $$$i + j$$$. Then we can increase $$$i$$$ to $$$1$$$ and do the same process.

    • »
      »
      »
      10 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      How to efficiently update all js?
      Using example fl0>fr0, j>0 won't give us a more optimal i+j, but how to update all i+js? If I update all js (all f[i+j]), time will be O(n*log a*log a) again.
      Even if I update just the smallest/optimal i+j, if I go through all i (so, in this scenario, I only have i for loop, I don't have two for loops for one vertice from Cartesian tree), in my code there is a loss of generality for fli>fri. Maybe fri>fli. Fl is non-incresing which means maybe there is some t, where i>t and fri>flt>=fri. And then fri and fli is not optimal i+j so I lose generality. (Although I agree there isn't a loss of generality for fli>fri when we have two nested for loops for each of vertices, because we can operate with j for loop, but, again, that is O(n*log a*log a).)

      • »
        »
        »
        »
        9 days ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        You only need one for loop and if you examine carefully, the loop actually goes through all needed $$$i + j$$$ values because either $$$i$$$ or $$$j$$$ has to be increased after each step. This is my implementation for reference:

          for (int i = 0, j = 0; i + j < MX;)
            if (fl[i] > fr[j])
            {
              f[i + j] = min(f[i + j], fl[i]);
              i++;
            }
            else
            {
              f[i + j] = min(f[i + j], fr[j]);
              j++;
            }.