Try all characters from 'a' to 'z', and assume that we want to get a string that consists only of this character. What greedy strategy should we follow?

B.

Spoiler

Suppose that there are C colors in total. Then, each ai must be either C or C - 1, and it means that the difference between the maximum and the minimum is at most one. Do some case-analysis using this fact.

C.

Spoiler

Suppose that H is not a multiple of h. Put a positive number in a cell if its row-number (0-based) is a multiple of h, otherwise put a negative number. Can you choose the "positive number" and the "negative number" properly?

D.

Spoiler

Create a new cell that keeps the xor of all elements. Each operation can be considered as a swap between this cell and another element in the sequence. Reduce it to a graph problem.

E.

Spoiler

Can you get YES/NO for a given pair of vertices (or more generally, a given set of vertices) in O(M)? Restate it in terms of graphs, then find an O(NM + N3) solution.

F.

Spoiler

The task is about grundy numbers. Can you get O(bellnumber(N)) solution by trying all possible grundy-number sequences? Can you reduce it to O(3N) by DP?

And his (nssprogrammer) comment votes reached -688, the worst record in entire codeforces. I think even comment that written "Is it rated?" or "Please upvote me!" can't reach this record. (Though I'm not sure if red coder comments "Is it rated?".)

And after that big achievement (and a -292This contest is helpless because it is first of yours, another -110 blog post, and a few more), the author of the second comment in the list now still has quite a positive contribution.

A legend.

(Btw would you mind sharing how you found out this ranking? – UPD Thanks Diversity for helping me out... It's here)

Man, you completely messed important piece of codeforces' history, namely history of second comment. Its original version was:

"Do you want to win a T-shirt? No , I dont . Do you want to learn how to design tasks for programming contest? No , I dont . Do you want to solve 7 tasks in 2.5 hours? No , I dont. So Codeforces Round #270 is not right for me. Have a nice day.",

nobody cares about current version (it was changed to it after it got that many downvotes)

I could find the necessary condition to transform a into b, but couldn't find the minimum number of moves. I guess, the minimum number of moves are either mismatches or mismatches + 1, but couldn't find their corresponding cases.

The idea is very similar to that of Google CodeJam 3. The number of mismatches is indeed a lower bound, but you need to find minimum number of cycles to which you can decompose the swaps, and you can do that by union find. I wasted an hour by failing to understand how exactly is the N-th value (xor of all A values) play a role.

Reduce the problem to finding the minimum number of moves needed to turn an array a into b, where a move is swapping the last element with any other element of the array.

Let the elements of array a be a0, a1, ..., an (an is equal to the xor of a0 to an - 1) and the elements of array b be b0, b1, ..., bn.

Add an undirected edge from ai to bi for all i. Let x be the number of mismatches in the array a and b (not counting an and bn). For each component that does not contain an and bn and has size ≥ 2, add 1 to the x. The answer is x.

Realize that the array has to be such that the difference between maximum and minimum values of the array is at most 1.

Now there are two cases, either all the values of the array are same. That is only possible if all people have distinct color hats, or nobody has a distinct color hat.

In the other case (when the difference is 1), let's assume the values are x and x+1, then all the people with value x must have a distinct color hat (i.e. each such person must have a color that no other person has). And for all the people with x+1, they should have a hat such that there is at least one other person, with value x + 1, that has the same color hat. Using this logic you will get an inequality. Code

I tried F. The graph formulation of Sprague-Grundy is that we need to split the DAG into layers such that from each layer, we have edges to all layers below and vertices 1 and 2 are in the same layer, which can be done using a DP picking whole layers and all edges into them at once in . However, I'm getting a different result on the last test, consistent with checking by hand. Is that the whole right idea or am I forgetting something?

I had the same situation with the following bug: when a certain layer contains one of (1,2), we're certain that we have achieved what we need, so I added 1 to the number of ways. But we need to add 2 to the power of the number of edges connecting yet unassigned vertices.

Divide the entire board into H/h * W/w submatrices. Sum of each such submatrix must be negative whereas the whole some must be positive, so you get a contradiction. For example, if W=H=4 and w=h=2, you have:

Usually I don't like the idea "set constraints as high as possible". One of our solutions worked in 133ms, but at the same time poorly written O(3nn) C++ solution took 2s. And it doesn't look nice if the intended complexity is O(3n * n) and the TL is 1s for n = 15.

My rule of thumb is that a theoretically good solution should theoretically pass (if the contestant got lucky and the constant didn't end up too big), so a very poorly (10x) written solution taking 2s means the TL should be 2s like normal.

Our color/dan scheme is very systematic. The range of each color is exactly 400. We added silver crowns for 3200-3600, and gold crowns for 3600-4000. The range of each dan is exactly 200. This is something that never decrease (so we use the peak rating), and is used in Go or Shogi (Japanese chess).

I thought I carefully chose parameters such that reaching red in AtCoder is as hard as reaching red in TC or CF, and reaching 4000 is barely impossible for humans. However, tourist beat the rating system today. Congratulations!

Does anyone have an idea for new color/dan? Note that usually the highest "dan" is 10.

Reduce the problem to finding the minimum number of moves needed to turn an array a into b, where a move is swapping the last element with any other element of the array (if you have trouble here, see the current editorial)

Let the elements of array a be a0, a1, ..., an (an is equal to the xor of a0 to an - 1) and the elements of array b be b0, b1, ..., bn.

Do coordinate compression on these numbers and suppose there are v distinct numbers. Construct a graph on v vertices with the following method :

Add an undirected edge from ai to bi for all 0 ≤ i ≤ n with ai ≠ bi. (We allow multiedges here)

Each edge of this graph describes a mismatched pair. Note that each vertex has even degree, as if x appears k times in a, then it must appear k times in b. Thus, each component has an Eulerian cycle.

Now, we can use these Eulerian cycles to construct the optimal solution. For the component containing an, we can perform the swaps according to the Eulerian cycle and use e - 1 swaps to accomplish the goal (where e is the number of edges in that component). After that, the last element will be bn and if the component containing bn is still unresolved, we can use e moves to resolve it, where e is the number of edges in that component. For every other component that does not contain an or bn, we require e + 1 moves to resolve that component. This summarizes to :

Let x be the number of mismatches in the array a and b (not counting an and bn). For each component that does not contain an and bn and has at least one edge, add 1 to the x. The answer is x.

" For the component containing an, we can perform the swaps according to the Eulerian cycle and use e - 1 swaps to accomplish the goal (where e is the number of edges in that component). After that, the last element will be bn and if the component containing bn is still unresolved, we can use e moves to resolve it".

I had some difficulty understanding this part because I was unable to understand why an and bn would be in different components (if an is resolved, then so is bn). If an != bn, they are in the same component as there is an edge between them. If an = bn, they are in the same component as they are the same node. Could you perhaps explain your statement with a small example? :)

I got AC adding e if an = bn, and e-1 if an != bn, where e is number of edges in the component of an.

Ya I didn't realize an and bn are already guaranteed to be in the same component by construction of the graph :P. You're right, we should add e if an = bn and e - 1 if an ≠ bn for the component containing an.