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

Автор Cirno_9baka, 5 лет назад, По-английски
Tutorial is loading...
solution

Idea: Cirno_9baka

Tutorial is loading...
solution

Idea: AquaMoon

Tutorial is loading...
solution

Idea: Cirno_9baka

Tutorial is loading...
solution

Idea: Cirno_9baka

Tutorial is loading...
solution

Idea: AquaMoon

Tutorial is loading...
solution

Idea: AquaMoon

Tutorial is loading...
solution

Idea: AquaMoon and mejiamejia

Tutorial is loading...
solution

Idea: ODT and box

UPD: Chinese editorial can be found here.

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

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

A concise solution for Div1A/Div2C (in D):

code

Explanation:

  • sort among even positions in the array
  • sort among odd positions in the array
  • check whether the array became sorted
»
5 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +115 Проголосовать: не нравится

Consider each position individually. There is always exactly one letter that occurs an odd number of times. So just take them out they are the letters of the stolen string.

If this is how you provide editorials? People referring to the editorial are those who couldn't solve the problem or those who have a lot of questions in their minds. You must elaborate your solutions as much as possible.

If you say, that I must be that smart to figure out what you want to say, thank you very much!
It's not just B, the editorial of problem D gets the same remarks from me.

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

    to be fair this problem is very simple and after getting the main idea it's not hard (the tricky part about the problem is just having the idea to store based on the position)

    The editorial is bad though, it's just that it makes sense to be concise on B specifically

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

      I can understand that you found this problem to be very easy. But it wasn't for me(and I know I am at fault here). But after all, I can expect a clean explanation so that I may know my mistakes(no matter how bad/silly they are I don't care).

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

        I don't think the problem is "very easy" (in fact i skipped that problem when i read it the first time), i just think the hard part was having the initial idea and from that point forward you can figure out what to do without much trouble. I do agree that this editorial is bad (i edited my comment shortly after), im just playing devil's advocate

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

Too hard.

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

The solution for B can be found with XOR since every element except for only one is appeared in even number of time => their XOR will be 0 and the odd one out will be revealed https://codeforces.me/contest/1546/submission/122098007 But the idea of counting in the map is ok though

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

sro lxl orz

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

Atleast provide solutions also with explanation beginners find it difficult to understand

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

In my opinion the problems are too hard for a 2.5h-contest :(

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

For B you can solve for each position the typical problem of finding the missing number, i.e. sum(all) — sum(present) = missing. 122094011

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

Worst editorial

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

Nice pretests for Div2 C )

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

Editorial to B is super weird xddd. "We can find that several operations mean we take out any group and insert it to any position to the chessboard." — what does that even mean xd?

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

My submission for div2 B got TLE on PyPy and got accepted with exact same code in Python, wtf? I used flush in both as stated in the problem.

TLE solution: https://codeforces.me/contest/1546/submission/122117451

Same code in Python accepted: https://codeforces.me/contest/1546/submission/122117803

I wasted around 1 hour because of this first I implemented the logic with normal arithmetic operations got TLE, then reduced number of loops got TLE, then changed arithmetic operations to bitwise operations as they are faster, using xor to get that odd one out, then too TLE, then I thought of switching from PyPy -> Python and it worked.

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

Great round but the pretests for div 2 C/div 1 A were not so strong.

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

Well... I tried Div1C and Div1D intensely for 2 hours. No programming — just writing on paper. In Div1D I could find the manipulated row, as described in the editorial and then I started choosing 3 consecutive unmanipulated arrays (such arrays always exist since $$$k \ge 7$$$ ) and search for arithmetic progressions/do some bipartite matching or stuff. In Div1C i tried connecting the arrays in a graph (two arrays are connected if they share an equal value) and then looking for subsets of $$$n$$$ arrays with no edge between them. But for both I couldn't find a real solution.

Now I read the editorial and the solutions are so beautiful! Really wonderful Problems.

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

    I hope you enjoy Div1C, because it's quite hard for me to generate the test data of it. Meanwhile, as a tester of Div1D, it cost me 5 hours to think, finally get ispiration to AC. In fact, I suppose it's the best problem of the contest.

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

      Using the ideas from the Editorial (Chosing rows greedy for Div1C and multiplying solutions by 2 if there is no unique greedy choice and sum of squares for Div1D) I was able to solve them both yesterday. Though I'm still thinking about the proof for C and my implementation for D is quite ugly still.

      Oh yes, I guess it's difficult to find meaningful testcases for Div1C. I had problems writing small meaningful testcases on paper to understand the problem.

      I really like both of them!

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

Div2 E and F were too hard, but I have to admit the solution is beautiful. Very clever problemseters!

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

Could someone explain B? I did not understand the editorial that much :c

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

    Add all the occurencies of each letter in each index (both before and after they get jumbled). Let's say we're trying to find which letter is in the stolen string on index i. Because every letter on the non-stolen strings appear twice, the letter on the original stolen string is the only one that appears an odd number of times in that particular index. If you do that to every index you'll get the answer

    My solution is a bit different but i imagine that's what the editorial was trying to say

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

    If the characters 'a','b','c' are at the first position of 3 strings and the given 2 flipped strings have characters b,c at the first position then we know that the string which had character the 'a' in the first place is missing. We can do this for each index.

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

    I took the sum of ASCII values of i'th(1<=i<=m) character of all the original strings and subtracted from it the sum of ASCII values of i'th(1<=i<=m) character of all the new strings.Then just accumulated the character for that value in a string.that's your output.Check my submission for clarity.

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

    A simpler implementation that I used was to just XOR all the ((2*n)-1) strings' characters for each index separately. The final XOR would be the stolen string.

    Since, every character except the ones in the stolen string occur a multiple of two times at their respective indices, the stolen string remains after XOR.

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

    We have to work this out character by character, as given n*m does not exceed 10^5, so we can loop through every character. loop thorough each character [j] in each string [i], Now for all the characters find that character which is not present at the jth index of the scrambled (n-1) lines. do this for every j 0-m, and you'll have a list of characters which are missing.

    Here's how I did it.
    Create a m sized vector<int> -- call it vans of size m, initialized with zeroes.
    Now for every line in the first n strings [i], loop through each character [j], find it's ascii value and add to vans[j].
    Now read the next n-1 strings, loop through each character [j], find it's ascii value and substract that value from vans[j].
    vans is now a vector of int storing the ascii values of missing characters.
    

    Print them out. https://codeforces.me/contest/1546/submission/122215500

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

Maaaan was I not ready for Div 1

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

How to solve problem div2 C, I don't understand the idea in the tutorial

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

A quick question — what’s the point of tests, if they don’t tell you your solution is wrong? I could probably have submitted code from 3 rounds ago and gotten AC.

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

Wrong answer on test 38

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

but how to calculate the number of good subsets in div2E? how to construct one is an obvious thing lol

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

Does anyone have the the proof or intuition about the problem Div2 C . Please explain it

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

    Lets say facing the right is position 0 and facing left is position 1, and say the person on index i gets to index j after sorting the array, which position would they be facing?

    Well, for that to happen we need at least abs(j-i) swaps and therefore just by doing that movement from i to j we would be in position abs(j-1)%2. The question is, can we still do swaps in a manner that will put us back at position j but will do a 1 (mod 2) number of swaps? The answer is no, because if we do x swaps to one side, we will still need x swaps to get back, and therefore it will be 2*x = 0(mod 2) swaps.

    Therefore if we store the indexes that a person of number x (in particular, the ammount of indexes with certain parity), we solve the problem because we just need to check if there are enough of those positions to acomodate all the people

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

    Subtask : lets assume all elements are distinct
    lets take one single element
    its position in array is y(eg:7)
    its position in sorted array is x(eg:4)
    now to move its position from 7 to 4 it will have to make min 3 swaps.

    NOTICE : if you would try to use one extra positon like 3 to reach 4 then it would have 5 swaps ( 7 to 4 , 4 to 3 and 3 to 4 ) . Thus we can confirm the parity of swaps dont change.

    Odd swaps : don't maintain the direction So we need even swaps.

    FINAL Task : Now elements are not distinct
    // now we have an opportunity to select a final position ( of duplicates)
    To make an even swap we can move from:
    1) odd pos in original array to odd pos in sorted array OR
    2) even pos in original array to even pos in sorted array

    Thus we are counting the no of odd and even pos of each element in original and sorted array

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

How was there not even a single pretest for C where a[i] was greater than n?

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

The round was amazing!

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

Is it even realistic to solve problem F in the duration of 2 hours 30 mins? Just looking at the editorial make me feels sick...

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

    I think there's a much simpler solution to F which is probably only a bit slower:

    Like the editorial, let's process a block of $$$b$$$ queries at a time. Then, instead of grouping by static/dynamic index, let's group by static/dynamic value. There are only at most $$$6b$$$ different values which change, namely the 3 old values of $$$b_{a_i}$$$, $$$a_i$$$, and $$$c_{a_i}$$$, and the 3 new ones for each changed index. For a single value, we can think solve this using a simple 4-state DP. Then, we can find the contribution of all static values for each prefix in $$$O(n)$$$ time, and we can maintain a segment tree of 4x4 transition matrices for each dynamic value to answer those queries. Overall, this will take $$$O((m/b)(n + b^2 \log n))$$$ time, and the optimal choice of $$$b$$$ gives $$$O(m \sqrt{n \log n})$$$. The constant factor seems a little high, but it seems like the editorial probably has high constant factor too.

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

So if the problems are written by only two writers, why do you give such a long writers' list?

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

Good problems but bad contest.

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

Editorials for problem div2B and div2C could've been much better!

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

Why was problem B interactive?

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

Can anyone explain Div2/D? Didn't understand the editorial.

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

Can someone tell me that , have I done some mistake in understanding Div2 C's statement , because I think this can be a valid steps of solution for test case 38 of Div2 C https://ideone.com/JhSefY

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

Can someone help why this solution to Div2.B failed FST?

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

Regarding Problem Div2 C and test case 38, I am unable to understand why it's answer will to be "NO".

Rather than considering the positions, let's consider the number of adjacent swaps it takes to make the array non decreasing.

[I have made the elements I am swapping bold]

2 1 2 1 2 1

1 2 2 1 2 1

1 2 1 2 2 1

1 1 2 2 2 1

1 1 2 2 1 2

1 1 2 1 2 2

1 1 1 2 2 2

So the swaps each element had to undergo to reach the final array are: 1 2 3 3 2 1

So in terms of direction L and R it will be transformed to: L R L L R L

It can be further transformed by swapping adjacent equal elements once, as follows:

L R L L R L

R L L L R L

R R R L R L

R R R R L L

Finally, we will get: R R R R R R

So, I can achieve all R's in the end and it's still non-decreasing.

Please correct me if there is a mistake here.

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

Thanks for nice contest.

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

For Div1D, changing every number so that $$$sum[y]$$$ is correct is not enough. Why is it enough to make $$$sum[y]$$$ and $$$sum2[y]$$$ have correct values?

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

    Because you can change any values to make $$$sum[y]$$$ correct but there is exactly one value that makes both $$$sum[y]$$$ and $$$sum2[y]$$$ correct. It's not the same but it's quite similar to how there is exactly one solution for $$$x$$$ and $$$y$$$ when we know $$$x + y$$$ and $$$x^2 + y^2$$$.

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

    Look at an alternative problem. You have an array. And you have to choose a single number to increment by D, such that the target sum of squares is S.

    This chosen number is unique. Why? Say we have two such numbers which when incremented give the same sum of squares x,y.

    $$$x+(y+D)^2 = (x+D)^2+y^2\implies 2Dx = 2Dy \implies x=y$$$ because D isn't 0.

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

My solution for Div2. C (although it feels like an overkill now, I hope it will help those who are looking for some sort of "intuition" here).

First of all, we can calculate the minimum number of swaps all elements must undergo in order to make the array non-decreasing. This can be done easily with the help of inversion counting (more specifically, for some index $$$i$$$, counting the number of elements smaller than $$$A_i$$$ to the right of $$$i$$$, and the number of elements greater than $$$A_i$$$ to the left of $$$i$$$.

If some element $$$i$$$ undergoes an even number of swaps, it stays correctly oriented, otherwise it gets flipped (incorrectly oriented).

After arranging the array in non-decreasing order, it is clear that all elements which have the same value, are together.

Let us assume a segment {$$$a, a, a, a, a, a, a, a$$$}, which is oriented {$$$L, R, L, R, R, L, R, L$$$}.

Let us pick $$$2$$$ $$$L$$$s such that there is no $$$L$$$ between them. We can correctly orient them with swapping among themselves, if the number of $$$R$$$s between them is even. So, we notice that we cannot correctly orient $$$1$$$ and $$$3$$$, but we can correctly orient $$$3$$$ and $$$6$$$, and after doing that, we again have an even number of $$$R$$$s between $$$1$$$ and $$$8$$$, so we can correctly orient them as well, thus orienting the entire segment.

To implement this part, I used a stack, in which, whenever I encountered an $$$L$$$, if it was possible to "cancel" this $$$L$$$ with the previous $$$L$$$, I greedily did it, otherwise I simply pushed this $$$L$$$ to the stack. After iterating over a segment of equal values, if the stack is finally empty, then we can be sure that the segment can be correctly oriented, otherwise we can be sure that the segment cannot be correctly oriented.

Although some might find it messy, here is my code for the same : 122139852

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

the pretest for C was so weak it made the contest not fair for some contestant

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

Can someone please tell me why my solution of A does not work?
122139278
Thank you

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

    I was doing the same mistake, this technique doesn't guarantee that you have done atmost 100 operations.

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

    The reason your solution is giving the wrong answer is, consider a case,
    1
    5
    1 6 5 3 1
    1 4 2 4 5.
    So, the test case is valid, and when your outer loop will come at i=3, your inner loop will increase a[i] by one at j=1, so now the array will look like this,
    a[]= 1 5 5 4 1,
    and inner loop further goes on and increase a[i] by one at j=2, and array will look like,
    a[]= 1 5 4 5 1,
    Which is a completely unnecessary operation. Though we are not required to minimize the moves, we are supposed to complete it in 100 operations. That's why it is giving the wrong answer.
    Solution: You can break the inner loop when a[i] becomes equal to b[i], Hope this solution would help, 122159718.

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

Why this solution for problem B (Div2) gets tle for large m (tc4)

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

    im gonna copy a comment i did to another person with the same problem

    "I think the problem is that intead of ans=ans+z.first; you should do ans+=z.first or ans.append(z.first), because in your code you are first making a copy of ans, then summing it with z.first, and only then atributing that value to ans. This is O(n^2) because for each iteration making the copy takes O(n).

    I think depending on the compiler your code could work though"

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

How to break D into a "Stars and Bar" technique problem?

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

AquaMoon wants to count the number of states reachable from the initial state with some sequence of operations. But she is not good at programming

has 2413 peak rating

I guess I should switch for programming microwaves.

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

Format of editorials with hints is much better

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

Как человек, у которого упало две задачи на систестах, выражаю недовольство этим раундом

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

Alternate approach for Div2 B. Just keep a count of characters appearing at indexes before and after the operation. The missing character would be a part of the answer for that index,
link- https://codeforces.me/contest/1546/submission/122093074

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

Any better explanation or intuition behind div2 D? Maybe some kind of strict proof.

Edit: I understand the part that the number of groups (if you calculate every time the way it is shown in the editorial solution) remains the same no matter what you do. But I wonder why would someone come up with such an idea? Was it a result of some observations?

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

Kept getting WA on 38th test case,Question C.Anyone else?

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

Here is a different way of approaching Div2D-

Lets call the ones between a 0 and the next 0 as 'gaps'. For example 110011101 has 4 gaps containing 2, 0, 3 and 1 ones respectively (assume that there are dummy zeroes in the beginning and at the end). Now notice how the one move in pairs and whenever an operation is applied, the number of ones in a gap decreases by 2 and number of ones in another gap increases by 2. This means that the parity of the number of ones in all gaps will remain consistent regardless of the state.

Count how many gaps have even parity and how many gaps have odd parity. Now we just need to count the number of ways to distribute the ones in the gaps such that the parities are maintained.

Lets assume that we have decided to distribute $$$x$$$ ones among the even gaps and $$$c$$$-$$$x$$$ ones among the odd gaps where c is the total number of ones.

If there are $$$e$$$ gaps with even parity, the number of ways to distribute the ones would be the same as finding the number of non negative integral solutions of the equation $$$a_1 + a_2 + ... + a_e = x$$$ such that all $$$a_i$$$ are even. This is the same thing as the stars and bars method.

Similarly if there are $$$o$$$ odd parity gaps, you need to find the number of solutions of $$$a_1 + a_2 + ... + a_o = c-x$$$ such that all $$$a_i$$$ are odd. The product of these two answers will be the number of distributions for a single value of $$$x$$$.

Iterate over all $$$x$$$ from 0 to $$$c$$$ and sum up the product of the two answers for each $$$x$$$.

Link to my submission

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

Is there are no prefix optimum solution in D (chess) ? I tried to use DP here but its incorrect.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится
When 'A' is a curse
»
5 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Woah, i didn't expected that Div1C and Div1D are so beautiful before reading editorial. Thanks!

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

Oh wow, it was rather easy to mess up m and k in Div1D and because of that I wrote a solution that works for at least 5 consecutive times instead of at least 7 (in which case it gets a lil bit easier cause I can take 3 consecutive valid measurements). I interpolated quadratic polynomial in my code and used doubles along the way ;p.

My solution is a bit different as well. As a "hash" of a multiset of integers $$${x_1, \ldots, x_n }$$$ I take $$$(\sum x_i, \sum (x_i-x_j)^2)$$$. You can see easily see that second value is a quadratic function of $$$t$$$ if we make variables $$$x_i$$$ linearly dependent on $$$t$$$, so by interpolating quadratic polynomial I can retrieve changed variable. Tbh I think my solution is just strictly worse than one from editorial ;p. But not by much.

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

    Here's another pretty simple solution that works for $$$4 \leq k$$$ just like the one above.

    Let $$$p_t$$$ be the array of captured coordinates at time $$$t$$$.

    Then, let's define $$$two_t=\sum p_{t,i}^2$$$. We can see that

    $$$ \begin{align*} two_t &= \sum (x_i+tv_i)^2 \\ &= \sum x_i^2 + 2t \sum x_iv_i + t^2\sum v_i^2 \end{align*} $$$

    We already know $$$\sum x_i^2=two_0$$$, so we only need to find $$$\sum x_iv_i$$$ and $$$\sum v_i^2$$$.

    Now find any two different times $$$t_1,t_2 \not\in \{ 0,y\} $$$ (this is where $$$4 \leq k$$$ comes from).

    Then using the expansion of $$$two_t$$$ from earlier, we just get a system of two linear equations with two unknowns:

    $$$ \begin{align*} two_{t_1} &= \sum x_i^2 + 2t_1 \sum x_iv_i + t_1^2\sum v_i^2 \\ two_{t_2} &= \sum x_i^2 + 2t_2 \sum x_iv_i + t_2^2\sum v_i^2 \end{align*} $$$

    Solving, we get

    $$$ \sum v_i^2 = \dfrac{t_2two_{t_1}-t_1two_{t_2}+(t_1-t_2)\sum x_i^2}{t_1t_2(t_1-t_2)} $$$

    and then just get $$$\sum x_iv_i$$$ from one of the equations.

    Now, we can just get the unmodified $$$two_y$$$ from the earlier expansion $$$\sum x_i^2 + 2y \sum x_iv_i + y^2\sum v_i^2$$$ , and solve the problem (the rest of the solution is the same as the one in the editorial): 122165319.

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

      Actually mine works for k=4 too, but I said k>=5, because during the contest I was thinking this is the actual constraint :D

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

        Oh, yeah it does, sorry:(, fixed the wording to make it obvious yours works for $$$k=4$$$ as well (it was super late when I was posting the comment, so I didn't check). I was actually about to post my solution as a separate comment, but then saw your comment, and decided to just reply to yours instead, so that the solutions would be grouped together (since our comments seem to be the only ones talking about Div1D's solution).

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

I think Div.1 A & B are interesting problems, because I have been gained -87 rating changes because of them. TwT

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

The problem are great!But they are too hard :(

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

Weak pretests of Div2.C...

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

In Problem B, why does running n*m where n >= 1e5 and m >= 1e5 doesn't get TLE? I was stuck because of this.

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

Please , someone make me understand Div2 A What is wrong in my submission 122158130

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

For problem E, it seems that the tutorial just gives the solution but I'm having a hard time understanding why it is correct. Can someone explain?

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

Proof for div1b-
First we will add 2 zeroes one at the beginning and one at the end.let x be the number of zeroes.let ai be the number of ones between the ith and (i+1)th zero for all 1<=i<=x-1 .Notice that the operation is same as subtracting 2 from one index(which has value atleast 2) and adding it to 2 to one of its neighboring index so the invariant is parity of ai.

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

I love the problems. Very nice ideas, and the solution is clear and easy to understand.

Thank you very much <3

(Actually I'm quite sad right now because I've just demoted to Specialist)

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

Can I get 46th test for Div 2 problem C?

It starts with: 1 100000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ...

But when I locally run test with "1 2" repeated 50.000 times I don't observe any performance problems. It seems the test is different from "1 2" repeated 50.000 times.

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

This may be an easy-to-understand Chinese editorial to C problem https://blog.csdn.net/qq_45863710/article/details/118674749?spm=1001.2014.3001.5502

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

Can someone help me to prove the author's solution for div2E div2.E problem E div2 div.2

Why the algorithm described above works?

And why is this? "If there not exists such an array discribed above, according to the Pigeonhole Principle, all numbers of the unchosen arrays must appear exactly twice on their columns" (typo btw :()

Any help will be highly appreciated. Thank you very much!

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

    We have the Chinese version of the prove, but we do not have the ability to translate it into English.

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

    Here is a proof on "If there not exists such an array discribed above, according to the Pigeonhole Principle, all numbers of the unchosen arrays must appear exactly twice on their columns".

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

    Div1 C:

    Situation 1: If an array have a number which appears exactly once at its column, then the array must choose, we can delete least two arrays(The array and arrays which with the array have common elements).

    Situation 2: All numbers of the unchosen arrays appear exactly twice on their columns. If not have situation 1. Then must is situation 2. In situation 2, we can choose any an array and delete the array and arrays which with the array have elements, meanwhile multiply the answer by $$$2$$$.

    Proof:

    Let the remained arrays set are $$$Q={array_1,array_2,...,array_{2*k}}$$$。 First we redefine Latin square:A $$$n*m$$$ matrix so that not any row or any column have common elements($$$n$$$ can not equal $$$m$$$).

    Then we define Two Latin square: A arrays set $$$Q$$$ of size $$$2*k$$$ so that we can divide it to two $$$k*m$$$ Latin square.

    Proof $$$Q$$$ is a Two Latin square: The conditions of the problem make we must can choose $$$k$$$ arrays from $$$Q$$$ so that the $$$k$$$ arrays is a Latin square. We consider the remained $$$k$$$ arrays, all number in a column appears exactly once, all row are a permutation of $$$1$$$ to $$$n$$$, the the remained $$$k$$$ arrays also is a Latin square.

    Define Minimal Two Latin square: Give a arrays set $$$Q$$$ of size $$$2*k$$$ which is a Two Latin square,we have an arrays set $$$A\subseteq Q$$$, let $$$B$$$ is the minimal arrays set so that $$$A\subseteq B\subseteq Q$$$ and $$$B$$$ is a Two Latin square. We call $$$B$$$ is the Minimal Two Latin square general by set $$$A$$$ and $$$Q$$$.

    We set $$$A={array_x,array_y}$$$($$$array_x$$$ and $$$array_y$$$ have common elements), obviously $$$array_x$$$ and $$$array_y$$$ can't choose same time. Let $$$B$$$ be the Minimal Two Latin square general by set $$$A$$$ and $$$Q$$$. Then $$$B$$$ can be divide to two Latin square unique. We choose $$$array_x$$$ or $$$array_y$$$ can uniquely determine the set reserved in $$$B$$$. And our choice will not affect how $$$Q-B$$$ chooses. We just need know set $$$B$$$ multiple the answer by $$$2$$$, and continue to choose from set $$$Q-B$$$.

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

      In your last paragraph above, can you describe what is set A? Does A have just two rows, or can it have more than two rows?

      If A is a set which has two rows, isn't B just equal to A?

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

        General speaking, we can divide $$$Q$$$ to some Minimal Two Latin square $$$B_1,B_2,...,B_t(B_i\cup B_j =\varnothing$$$ for $$$i\neq j)$$$, so that the answer is $$$2^t$$$.

        In each $$$B_i(1\le i\le t)$$$, we can find a $$$A_i={array_{x_i},array_{y_i}}$$$ so that $$$A_i\subseteq B_i$$$ and $$$array_x,array_y$$$ can't be choose same time. Use $$$array_x$$$ or $$$array_y$$$, we can uniquely make sure a choose way in $$$B_i$$$.

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

Can anyone please help to point out the mistake in my submission Div2C https://codeforces.me/contest/1546/submission/122161335 I would be thankful for pointing out what i am missing. Thanks

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

    There seems to be an out of bounds array access bug in your code, because you do a[i + 1] indexing without ensuring that i + 1 < n. However this is not the real reason for getting a WA verdict.

    Please consider 7L 7R 7R 7L pattern as a part of your sorted array. Your code will report that the answer is NO after checking the first two elements. But the real answer is YES, because we can swap the middle two elements to get 7L 7L 7L 7L and then swap the first two elements to get 7R 7R 7L 7L. After that, the last two elements can be swapped too: 7R 7R 7R 7R

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

Div1 C:

Situation 1: If an array have a number which appears exactly once at its column, then the array must choose, we can delete least two arrays(The array and arrays which with the array have common elements).

Situation 2: All numbers of the unchosen arrays appear exactly twice on their columns. If not have situation 1. Then must is situation 2. In situation 2, we can choose any an array and delete the array and arrays which with the array have elements, meanwhile multiply the answer by $$$2$$$.

Proof:

Let the remained arrays set are $$$Q={array_1,array_2,...,array_{2*k}}$$$。 First we redefine Latin square:A $$$n*m$$$ matrix so that not any row or any column have common elements($$$n$$$ can not equal $$$m$$$).

Then we define Two Latin square: A arrays set $$$Q$$$ of size $$$2*k$$$ so that we can divide it to two $$$k*m$$$ Latin square.

Proof $$$Q$$$ is a Two Latin square: The conditions of the problem make we must can choose $$$k$$$ arrays from $$$Q$$$ so that the $$$k$$$ arrays is a Latin square. We consider the remained $$$k$$$ arrays, all number in a column appears exactly once, all row are a permutation of $$$1$$$ to $$$n$$$, the the remained $$$k$$$ arrays also is a Latin square.

Define Minimal Two Latin square: Give a arrays set $$$Q$$$ of size $$$2*k$$$ which is a Two Latin square,we have an arrays set $$$A\subseteq Q$$$, let $$$B$$$ is the minimal arrays set so that $$$A\subseteq B\subseteq Q$$$ and $$$B$$$ is a Two Latin square. We call $$$B$$$ is the Minimal Two Latin square general by set $$$A$$$ and $$$Q$$$.

We set $$$A={array_x,array_y}$$$($$$array_x$$$ and $$$array_y$$$ have common elements), obviously $$$array_x$$$ and $$$array_y$$$ can't choose same time. Let $$$B$$$ be the Minimal Two Latin square general by set $$$A$$$ and $$$Q$$$. Then $$$B$$$ can be divide to two Latin square unique. We choose $$$array_x$$$ or $$$array_y$$$ can uniquely determine the set reserved in $$$B$$$. And our choice will not affect how $$$Q-B$$$ chooses. We just need know set $$$B$$$ multiple the answer by $$$2$$$, and continue to choose from set $$$Q-B$$$.

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

How would we solve problem B of div2 if it was asked that every person in the end will look towards left?

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

can anyone could give me intution for div2D i can understand why are we not including no of groups also ? why only '0' and '11' are considered why not '1' also

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

    because it cannot propagate imagine a string "001010" the no of combinations of it is 1 (itself) but now add just one pair of 11 in the string lets just add it in the beginning "11001010"

    and now see its transformation

    01101010 00111010 00101110 00101011

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

    Looking at a simple example would be the simplest i guess. E.g. ..11...1.. has these possible states:

    11.....1..
    .11....1..
    ..11...1..
    ...11..1..
    ....11.1..
    .....111..
    .....1.11.
    .....1..11
    

    We can see, this looks likes this: we have one state with all 3 ones touching. Every other state has a single 1 and a double 11. Let's mark the first 1 of a 11 group with X

    X1.....1..
    .X1....1..
    ..X1...1..
    ...X1..1..
    ....X1.1..
    .....X11..
    .....1.X1.
    .....1..X1
    

    Now let's delete every 1 in this diagram.

    X.......
    .X......
    ..X.....
    ...X....
    ....X...
    .....X..
    ......X.
    .......X
    

    We only have left the X and it occupies all possible states. You can make the same with some more complicated example, which I will put in a spoiler. Hope this gives you the Intuition about how the pairs behave!

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

Problem D(div 2) solution, what's mean "—" ?

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

Can anyone translate the Chinese editorial for E into english? https://www.cnblogs.com/invisible-eyes/p/15003033.html

It seems like the Chinese editorial has much more detail than the English editorial for that problem. I am still struggling to understand how to solve E. Thanks in advance.

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

the worst round, i've ever seen.

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

can anyone explain div.2 D in a better way pleasE?

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

Ah, it's very friendly for me to write a Chinese editorial:)

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

Why "NO" in 6 2 1 2 1 2 1

Consider it +2 +1 +2 +1 +2 +1

now swap (1,2) -1 -2 +2 +1 +2 +1

now swap(3,4) -1 -2 -1 -2 +2 +1

now swap(2,3) -1 +1 +2 -2 +2 +1

now swap(5,6) -1 +1 +2 -2 -1 -2

now swap(4,5) -1 +1 +2 +1 +2 -2

now swap(3,4) -1 +1 -1 -2 +2 -2

now swap(2,3) -1 -1 +1 -2 +2 -2

now swap(1,2) +1 +1 +1 -2 +2 -2

now swap(4,5) +1 +1 +1 +2 -2 -2

now swap(5,6) +1 +1 +1 +2 +2 +2

and its sorted with all right

can anyone tell

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

I will write down the intuition I got from Div2E/Div1C so that I can get it fixed in my brain.

Consider that the latin square we will choose is something like this (have numbers 1,...,n as the first column):

1----------

2----------

3----------

...

n----------

And the corresponding dirty square is something like this (have numbers a1,...,an between 1 and n as the first column):

a1----------

a2----------

a3----------

...

an----------

If i appear only once in the first column of the the 2n x n matrix, then we know that the row

i----------

belongs to a latin square. Indeed, if it was in a dirty square, then there would also exist a row

i++++++

in the latin square (because the latin square must have all elements 1,..n in its first column), what is a contradiction.

If no element appear only once in the first column of the 2n x n matrix, then each element must appear twice. Indeed, suppose an element appear k > 2 times in this column. One of these times must be inside of a latin square and the other k-1 times must be in the corresponding dirty square. But now it rest only n-(k-1) places in the first column of the dirty square. So we can only put at most n-(k-1) different elements from 1,..n at these places. So at least one number i from 1,..,n have no place to go inside the first column of the dirty square, which means that it only appears in the latin square (necessarily once), what is a contradiction to our initial hypotheses that no element appear only once in the first column of the 2n x n matrix.

This can be extended to any column.

What the algorithm proposed in the editorial do is construct a solution greedily. It keeps a set A with the choosen rows and a set B with the trash rows. If there is a row that is necessarily in a latin square, it picks it, put it in A and put in B all rows that can't be in a latin square with it.

If all elements appear twice in its column at some point (when we have 2*k elements), it means we have at least two latin squares. Suppose two of them are of the form

1----------

2----------

...

k----------

Then we know that all other latin squares generated by this configuration is an exchange of blocks

i----------

...

j----------

between these two initial latin squares. So we know the total number is something of the form $$$2^x$$$, but we just pick one factor two and continue breaking because we will have the other factor twos when we arrive to this situation again later.

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

I solved D without proving