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

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

Thank you for your participation!

Rating Predictions

2003A - Turtle and Good Strings

Hint
Solution
Code

2003B - Turtle and Piggy Are Playing a Game 2

Hint
Solution
Code

2003C - Turtle and Good Pairs

Hint
Solution
Code

2003D1 - Turtle and a MEX Problem (Easy Version)

Hint
Solution
Code

2003D2 - Turtle and a MEX Problem (Hard Version)

Hint
Solution
Code

2003E1 - Turtle and Inversions (Easy Version)

Hint 1
Hint 2
Solution
Code

2003E2 - Turtle and Inversions (Hard Version)

Hint
Solution
Code
Bonus

2003F - Turtle and Three Sequences

Hint 1
Hint 2
Solution
Code
Разбор задач Codeforces Round 968 (Div. 2)
  • Проголосовать: нравится
  • +117
  • Проголосовать: не нравится

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

ProofByACForces :)

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

Thanks for fast editorial.

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

Thanks for the amazing contest :) What topics should I learn To solve D2?

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

i panicked and got 2 WAs on A, and then got 2 unnecessary WAs on D1 with some spaghetti code. fml

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

very nice problem set.

enjoyed solving problem $$$D$$$.

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

Amazing contest and GREAT IDEAs !!!

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

In my solution to F, the probability of not obtaining the optimal solution is $$$(\dfrac{5!-1}{5!})^{600} = 6 \cdot 10^{-3}$$$ which is actually not very good. But there are only 65 tests so I passed pretests :)

Upd: Passed System test, seems that I'm lucky :)

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

In problem C solution:

Begin by placing x−y instances of the most frequent character at the start.

Why is this optimal? Why not just alternate most frequent character not only with the second most frequent, but with others as well? The rest is obvious but this part is just an assumption basically.

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

    Going further, does the order of frequencies really matter? Don't we just need to alternate characters in lexicographical order until there are no more left?

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

      This does indeed work, because consider this algorithm:

      At the first position place any character. At the $$$i$$$-th position place any character that is different from the one that you placed at $$$i-1$$$-th position. This algorithm will stop only if you exhausted all characters, or if you have left only characters of one kind $$$c$$$. Then place all the remaining $$$c$$$'s at the end.

      In this way you will have at most 1 segment of the same characters of length more than 1 (at the end). I think this is the same result the editorial solution gets.

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

    I tried alternate most frequent character with all others, it passed pretests.

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

    It's not so hard. There's something much easier than this solution.

    Just sort the string then print them in an order like $$$1,n,2,n-1,3,n-2,\dots$$$, and that's all.

    But I just can't prove it.

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

      I did the same thing. I wasn't too sure about my solution so I proved it and that made me submit the problem after one hour.

      I guess it works because you don't actually care too much about the characters themselves, but only about the changes.
      Define a change as the number of $$$i$$$ such that $$$s_{i}\neq s_{i+1}$$$.
      - If in a given substring you only have zero changes, then the first character is equal to the last and that is good.
      - If you have only one change then your substring looks like "aa...aabb...bb". Let $$$i$$$ be the only change, the only index such that $$$s_{i}\neq s_{i+1}$$$, you have that $$$s_{i}=s_{l}$$$ and $$$s_{i+1}=s_{r}$$$ (where $$$l$$$ and $$$r$$$ are the first and the last character of the substring), so $$$(l,r)$$$ isn't a good pair.
      - If there is more than one change it's good. If there are three or more different type of characters you can obviously find a change such that $$$s_{i}\neq s_{l}$$$ or $$$s_{i+1}\neq s_{r}$$$. If it is made only of two type of characters the substring has a block of characters of the first type, then a block of the second type, a block of the first, and so on... So if you take look at the second change you'll have that $$$s_{i}$$$ is of the second type and is different from $$$s_{l}$$$, and $$$s_{i+1}$$$ is of the first type so it is different from $$$s_{i}$$$. Note that it doesn't matter if $$$s_{i+1}=s_{r}$$$ because you know that $$$s_{i}\neq s_{l}$$$.

      Now, sorting the string as you said is optimal because you minimize the number of $$$i$$$ such that $$$s_{i}=s_{i+1}$$$ so you maximize the changes in every substring. And in particular there will be zero such indices unless there is a type of characters which occurs more than $$$\frac{n}{2}$$$ times, case in which you can't do better.
      In this sorting every substring will have one change only if the size of the substring is 2. Here you know you can't do better because in a substring with only two elements you can have zero or one changes, but having zero instead of one won't increase the number of good indices because regardless of the sorting, there are $$$x$$$ characters of that type and the substring with that character in the first and last position will always be $$$\frac{x(x-1)}{2}$$$.

      Hope that helps :))

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

        I don't think this is true. Using order 1, n, 2, n-1, ... does not maximize the changes.

        Imagine the sequence 1, 2, 2, 2, 3. Using the order 1, n, 2, n-1, ... we would get 1, 3, 2, 2, 2. This is two changes. We can get five changes with the sequence 2, 1, 2, 3, 2.

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

      Doesn't this not work for initial string "baa" which makes the new string "aba" which has less pairs than the original?

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

    OK, so I've thought about it, here's a better proof at least for me to understand. Let's just alternate characters, it's optimal because of the sum we need to minimize. If the most frequent character appears less than n/2 times in the string then we can alternate easily. Otherwise we can cap the most frequent character occurrence by n/2 and build an alternating string, but then we will have a block of the same characters left that we need to insert in the string somewhere. We can insert it only at the beginning or the end, because there it's going to be calculated in the sum only once.

    Pretty good problem actually, if you think about it, thanks.

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

Super fast Editorial...

btw problems were good <3

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

Anyone has a solution for F without using randomization? I tried to using some kind of meet in the middle, but it's too hard to merge the answer

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

    Here's a deterministic solution:

    Let's refer to elements with the same $$$b_i$$$ as a "class".

    Loop through all possible values of $$$2^{nd}$$$ and $$$4^{th}$$$ numbers and check the validity of the pair. Now, we have three more elements to fill: the one to the left, between two numbers, and the one to the right. For each of these, we know the range of possible values of $$$a$$$.

    Notice that if we consider the five best classes of elements of a set (with the highest maximum cost of elements belonging to that class), then the best element to select in this set will always be among those 5 (the other ones can ban at most 4 classes). So, we need the five best classes for all prefixes with $$$a$$$ bounded from above by the next element, and for all suffixes with $$$a$$$ bounded from below by the previous element. This can be precalculated easily in $$$O(n^2)$$$.

    The interesting part is what to do with the middle elements (they have both upper and lower bounds for $$$a_i$$$). We can maintain a segment tree that works sort of like a merge sort tree, but only stores the 5 best classes. The "key" will be the value of $$$a$$$. The segment tree is cleared for each new value of second element, and as we iterate over the fourth elements, we add all the stuff that we already passed to the segtree. So, we can get the middle elements in $$$O(5 \log n)$$$.

    Finally, we just have to merge the three groups of $$$5$$$ values using $$$5^3$$$ time.

    The final time complexity is $$$O(n^2 \log n + n^2 5^3)$$$, or $$$O \left( n^{\lfloor \frac{m}{2} \rfloor} \left( m \log n + m^{\lceil \frac{m}{2} \rceil} \right) \right)$$$ in the general case, which is (barely) good enough.

    P. S. Please excuse my usage of numbers inside $$$O()$$$ notation here, it was just too convenient to write it like that :)

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

      I think this meet-in-the-middle solution works in $$$O(24 * n^2)$$$: 278171336.

      I maintain the top 3 answers for pairs ending at i as L[i], and for pairs starting at i as R[i]. Since all pairs ending at an index have the color of that index, we need to store the best 3 pairs of different second color. So L[i] would have answers with (x, b[i]), (y, b[i]), (z, b[i]).

      Now we can brute-force the 3rd element $$$i$$$ (when k = 5) and merge it with the best 1st and 2nd element across all L[j] (j<i) (there are at most $$$3\times (i-1)$$$ options stored). The only difference is that in this merge, we need to maintain the top 4 answers ignoring the color of $$$i$$$ itself. For example, if (x, y) are the colors of the best 1st and 2nd elements, we need to store the top answer for each of these 4 combinations: {includes x or not} $$$\times$$$ {include y or not}. This is because the best 4th and 5th elements may need x, y, or both of them.

      Finally we do the same but to the right, and then merge the left and right answers at each 3rd element $$$i$$$ and maximize.

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

      I got the same idea and had a bad time inplementing that :)

      The constant factor is too large for the segtree part and I can only store the 2 biggest values. Beside that some optimizations on the constant factor is also needed for me.

      Anyway the data was weak enough for that to pass 278190335

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

    The technique in Problem F can be directly derandomized.

    We need a family of hash functions $$$\mathcal{H} = \{ h_i \colon [n] \to [k] \}$$$ such that for any subset $$$S \subseteq [n]$$$ of cardinality $$$k$$$, there exists a hash function $$$h_i$$$ in $$$\mathcal{H}$$$ that satisfies $$$h_i(S) = [k]$$$. This is known as an $$$(n,k,k)$$$-splitter. Once we have such a splitter, we can solve the problem by trying each hash function $$$h_i$$$ from this family.

    Randomly selecting a hash function is likely sufficient with high probability when $$$|\mathcal{H}|$$$ is sufficiently large. Note that for each $$$S$$$, the probability that none of the $$$h_i$$$ splits $$$S$$$ is

    $$$ \left(1 - \frac{k!}{k^k}\right)^{|\mathcal H|}, $$$

    there are $$$n^k$$$ many such subsets, so we need

    $$$ n^k \left(1 - \frac{k!}{k^k}\right)^{|\mathcal H|} \leq n^k \cdot \exp\left( - \frac{k!}{k^k}|\mathcal H| \right) $$$

    is much smaller than $$$1$$$. We need to take $$$|\mathcal H| \geq \frac{k^k}{k!} \cdot k\log n$$$.

    The difference between the analysis above and the official solution is that, once you generates a good $$$\mathcal H$$$, it doesn't only works correctly for a current test case, it universally works for all test cases! One practical solution is to hardcode a random seed in your program that has been verified to generate a splitter $$$\mathcal{H}$$$.

    BTW, the explicit construction of an $$$(n,k,k)$$$-splitter is theoretically nearly settled by the paper "Splitters and Near-Optimal Derandomization". The authors show how to construct a family of size $$$e^k k^{O(\log k)} \log n$$$. Note that the probabilistic method gives $$$\frac{k^k}{k!} \cdot k\log n$$$, and since $$$\frac{k^k}{k!} \approx e^k k^{1/2}$$$, the explicit construction is quite close to the probabilistic bound.

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

    Thanks for your help, I have got AC using some kind of MITM :). Feel free to hack my submission!

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

In the problem C, can we just rotate the character of array and just print it?? or missing something!?

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

D1 was nice :)

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

got TLE on D at the last minute by using loop from 0->m :)

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

terrible contest! D is much easier then C, B can only be guessed, not solved.

Also I got RE26 on D2 using c++20 and WA30 using c++17, how can this be?

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

My first contest with AC on div2C. ThankyouThankyouThankyouThankyou!

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

W contest!

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

It seems that the "In this version of the problem, you can choose the same integer twice or more" suggests the hint "choose the same integer twice" obviously. But D2 is a good problem for Codeforces div2 D. I guess the difficulty of it is *2000.

I want to mention that I do too much guesswork in this round. Especially B and C. Although it doesn't matter that this round is a good round for me. Thanks.

:D

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

Problem D is really cool!

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

Weak system tests for C.

My code: 278099825

A very stupid mistake, I forgot to sort the characters by how often they occur in s, as a result for the test:

1

4

ddbc

My code outputs: bcdd (which has 2 good pairs: (0; 2); (0; 3))

One of the correct answers: dbcd (which has 3 good pairs: (0; 2); (0; 3); (1; 3))

Despite this, my code has passed the system tests and got AC

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

I think it's harder to find the right strategy in C than in D1.

Thanks for D2. It was fun

(And yes, I will finally turn blue)

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

Alternate solution to E1 :

Lemma 1 : Every interval must have either exactly 1 0, or exactly 1 1(where the definition of 0s and 1s are same as editorial)

Proof : The optimum solution must be a local minimum. Fix the other segments and vary the number of 0s and 1s in one segment, it is a quadriatic function with central maxima. Hence, it is minimized at the ends of allowed ranges.

Lemma 2 : Some prefix of intervals will have 1 1, and some suffix will have 1 0, proof is left as an exercise

Just brute the prefix, and find cost to get O(m^2). Extending to E2 is trivial as left as an exercise. This can probably be extended to get a near-linear solution by computing cost(prefix + 1) — cost(prefix) fast, but i am too lazy to work out the details.

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

    Here's a $$$\mathcal{O}(m)$$$ solution for E1 278231107

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

in problem F, why is the probability of getting the optimal solution in one attempt is $$$\frac{m!}{m^m}$$$ ?

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

    Consider a set S = {s[1],s[2],...,s[m]} of all distinct b[i] in an optimal answer. To be able to get this answer from bitmask dp, all f(s[i]) must be distinct, where f(x) is mapping from x to a random number in [1,m]. The number of such mappings is m!*(m^(n-m)), m! is because f(s[i]) must form a permutation, m^(n-m) is because for any b[i] not included in S ,f(b[i]) can be any number and it doesn't affect answer. Number of all possible mappings is m^n, since for each b[i] there are m possibilities. Then, the probability of finding a mapping, where we can get an optimal answer is m!*(m^(n-m))/m^n = m!/m^m .

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

Hi, please check this 2 submissions, they have mostly the same code, the only difference is that the vectors are global in the first one. The second code gives TLE and by a big margin. Is this a bug or what? https://mirror.codeforces.com/contest/2003/submission/278156729 https://mirror.codeforces.com/contest/2003/submission/278156524

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

top 3 reason for depression

  1. breakup

  2. Substance Abuse

  3. WA in div2 A

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

I solved F deterministically in $$$\mathcal{O}(n^2 * k^3)$$$:

Let’s say we compute $$$dp(i,j)$$$ = answer if we have to take $$$j$$$ elements from the suffix of the array starting at position $$$i$$$. In order to avoid repeating some values from $$$b$$$, we also store the vector of chosen values (let’s call it $$$V$$$).

The issue is that choosing exactly those values may “block” you later. To prevent this, we also compute the best answer if we avoid using each of the values from $$$V$$$ separately. It’s easy to see that one of these $$$k+1$$$ candidates will be optimal.

Although my code’s complexity is $$$\mathcal{O}(n^2 * k^3)$$$, I believe it can be improved to $$$\mathcal{O}(n^2 * k^2)$$$. Given that I got AC in the last 12 seconds of the contest, I didn’t have time to even think about optimizing anything.

Here is my submission: 278149543 :)

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

I really can't get this: the first player can remove a number adjacent to a larger number, while the second player can remove a number adjacent to a smaller number.

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

Hey everyone, does anyone have any advice for coming up with proofs for problems (apart from solving more problems or working with smaller cases)? I have realized that I can often think of the solution, but can't prove it, so I don't end up implementing it. Any help would be greatly appreciated! :D

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

    well I think it's fine to try and implement a solution even if you haven't completely proved it. while implementing it, you might actually notice the flaw and then you can correct it, or start coming up with a new solution. this can waste a lot of time, if you're not efficient at implementing, but it's a decent approach if you find yourself not being able to prove easy problems

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

What topics should I learn to solve D1 and D2?

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

I got compilation error twice in B, when I was using g++20, but the same code got accepted in g++17. Why did this happen?

Compilation error 1 : https://mirror.codeforces.com/contest/2003/submission/278061013

Compilation error 2 : https://mirror.codeforces.com/contest/2003/submission/278072152

Pretests passed : https://mirror.codeforces.com/contest/2003/submission/278078881

delayed my submission from 8 mins to 22 mins :(

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

I guessed B and C

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

Can anyone please explain, how, in example 1 for problem D1, f(4) = 4

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

can someone help me with problem D1?

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

    the result of mex(x,ai,1,ai,2,…,ai,li) for every sequence is only two possible mex!
    for example a0= {0, 1, 3, 4} the mex of this sequence is {2, 5}
    if(x == 2) mex = 5, else mex = 2. and since i can choose every sequence multiple times, then whatever the value of x is, i can get 5 (f(2) --> 5, f(number != 2) --> 2 --> f(2) --> 5)
    so calculate each two mex for all sequence and choose the max_mex then the result is
    (max_mex * numbers_less_than_or_equal_to_max_mex) + (max_mex + 1) + (max_mex + 2) + .... + m

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

278173974 (D2) I think the approach is similar to the editorial sol but I have no clue why it's failing, can someone help?

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

I made a big mistake of starting to code problem D before working the example cases to ensure i understood the problem. Too bad I missed a crucial part even after the notification during contest that we can pick multiple sequence and moreover we can pick the same sequence any number of times. This misunderstanding led me to solve a completely different problem.

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

E1 (Edit: and E2) can be solved in O(n) time:

Solution for E1
Solution for E2

Implementation for E1 is very straightforward: 278182451. E2 is a little messier, but still not that bad: 278261466

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

Thank you for interesting problem.I've got +64!

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

Can someone help me with my solution of d2,which got WA on 27?

278147838

Thanks

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


In problem D2, how is the answer to the 3rd test case 1281?

Test case:
2 50
2 1 2
2 1 2
Answer: 1281

In my calculation, only 0 is the only value on which an operation can be made to get the 3. For other values (1 — 50), just take the value itself to get a better answer. So, it's the same as: 1+2+3+...+50. And, we'll get 1275 and +3 (that we got from the value 0). Then in total, it'll be 1278.

But I didn't understand how the answer was 1281. Where is this extra 3 coming from?

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

https://mirror.codeforces.com/contest/2003/submission/278211183

this is my submission can anyone help me which case i am missing ??

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

Can someone tell me why my code Wrong on C test3

wrong answer Participant's answer isn't a permutation of the given string. (test case 267)

278220017

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

The solution of D1 was O(n * l) and 1 ≤ n ≤ 2⋅10^5, 1 ≤ l ≤ 2⋅10^5 then why it does not give TLE

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

I need some help with debugging my code, I seem to have every edge case covered, yet I find myself with a WA on Test 27 :( https://mirror.codeforces.com/contest/2003/submission/278263899

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

Solution to E1/E2 was a little hard to understand, so I'll write mine

Separation of numbers into small/big parts was also very hard to understand, so I'll write the explanation too

Consider the border of $$$max\ a_i = A$$$. Now, for some optimal answer convert every number into $$$0$$$ if $$$\leq A$$$ and $$$1$$$ otherwise. It's guaranteed by construction, that all numbers in the left parts are $$$0$$$ and right parts are $$$1$$$. On the other hand, if we have some 01 coloring, we can provide an answer greedily. That's why the iff (if and only if) statement is true.

Now let's solve the whole problem. What do we want the segments to comply with in a 01 coloring? The leftmost element must be $$$0$$$, the rightmost element must be $$$1$$$ and the numbers in the segment must be non-decreasing, or in the other words for each $$$i$$$ in $$$(l, r]$$$ $$$c_{i - 1} \leq c_i$$$ must be true.

Let's try and build some DP, in which checking this would be easy. We want to be able to check the previous number and update the total number of inversions. I think the most straightforward DP to try here is $$$dp[prefix][count\ of\ 1][last element] = \text{the max number of inversions on a prefix with given number of ones}$$$. The transitions are easy. If we add a $$$0$$$, it's the smallest number amongst the prefix, so we need to add $$$prefix$$$. If we add a $$$1$$$, it's the smallest number amongst ones, so we add $$$count\ of\ 1$$$.

Now, how do we check the conditions on the segments? Just don't iterate over states and transitions that are impossible. If the current number is fixed, just iterate over it. If we should check index $$$i$$$ to be not less than $$$i - 1$$$, do that. That's it.

Solution 278270951

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

Can anyone please explain to me how the following tc answer is 16 for D2? 3 4 2 0 2 3 2 3 3 4 7 0 1 5 isn't here f(0)=3, f(1)=3, f(2)= 2, f(3)=3, f(4)=4? and total is 15.

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

O(N) solution for E1. The logic is based on examples and reasoning, despite not a complete and rigorous proof. https://mirror.codeforces.com/contest/2003/submission/278303362

The idea is to assign value 0 or 1 to a signature array that can be used to uniquely yield the optimal permutation (similar to the concept in tutorial). There are 2 separate passes. In the first pass, we handle intervals in head and tail and meet in the middle, and maintain counters for number of 0 in prefix and number of 1s in suffix. It is optimal to place 0111...1 in head if pre0 <= suf1 and otherwise place 00...01 in tail. In the second pass, we handle indexes not within any interval. In this phase, it is optimal to have value 1 at the index if pre0 < suf1 and 0 otherwise.

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

Hi, this is my first comp, but had a little trouble understanding q A. The editorial says, the answer is just comparing the first and last letters of the string, but couldn't you split the string up in such away, that substrings 1st and last letters would be different without the first and last letters being the same? For example the string "AABA", though the first and last letters do not match, cant we divide the string like this? — "A", "AB" and "A", such that i can just choose t0 to be "A" and t1 to be "AB", The first and last being different? Maybe I didn't properly understand qA?

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

    U are right but T1=AB and T2=A, so the first and last character match for i=1 and j=2.

    As for the solution, it's standard greedy solution. If the first and last characters donot match, we can split the string in 2 parts. First part has all characters except the last one and second part has the last character from s.

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

Love the rating predictions! Would love to see those on more editorials

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

Can someone tell me why my solution of D1 is not Working?

https://mirror.codeforces.com/contest/2003/submission/278484674

I doing exactly The same thing as the editorial aren't i?

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

problem D1 and D2 are beast... D1+D2 cost me 3 hours to upsolve it. DP on graphs are sure tough one.

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

In the editorial solution for D2, why are we allowed run a loop from $$$0-\min(m,k)$$$? I think I am missing something obvious, but according to the constraints the maximum value for $$$m$$$ is $$$10^9$$$. $$$k$$$ from the editorial is the $$$mex$$$ so theoretically they can reach the similar range for $$$a_i$$$ which is also $$$10^9$$$. Would it not result it TLE?

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

nice problem

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

"Otherwise, for $$$m≥2$$$, it can be inductively proven that ..." (Editorial for C)

I did the proof as an extra exercise, and it was not that easy. Considering that the problem is rated 1200, maybe the solution is easy to guess... but I think the real difficulty (including the proof) would be around 1600.

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

E1/E2 can be easily solved without DP: 331319759