先坑着。。。

Problem A. Asymmetric Art.

This problem can be solved with backtracking. The straightforward backtracking tries all possible subsets, but that’s obviously too slow. We can do several optimizations: first, let’s consider the numbers in increasing order, and when taking each number we can ‘mark’ all numbers that we can’t take anymore because of this new number. This is not fast enough, but we can additionally truncate our search by saying ‘if we’ve reached number x, then we’ll take not more than answer[n-x] more numbers’, where answer[y] is the number of items in the largest quasi-symmetric-triple-free subset for n=y. Then we can find all answer[] values in under one minute, and then send a program that has all answers hardcoded for judging.

于是 .. .

.. . bool dfs(int k = 2){ if (SZ(A) + F[n-k+1] <= F[n-1]) return false; if (k > n){ R = A; return true; } else { if (dfs(k+1)) return true; if (C[k]) return false; Push(k); bool flag = check() && dfs(k+1); Pop(k); return flag; } } .. .

表：

RD =->{gets.to_i} $stdin.reopen('art.in',"r") $stdout.reopen('art.out',"w") z=["0\n", "1\n1", "2\n1 2", "3\n1 2 3", "3\n1 2 3", "4\n1 3 4 5", "4\n1 2 3 6", "5\n1 2 5 6 7", "5\n1 2 3 6 8", "6\n1 2 3 6 8 9", "7\n1 2 3 6 8 9 10", "7\n1 2 3 6 8 9 10", "7\n1 2 3 6 8 9 10", "8\n1 2 3 6 8 9 10 13", "8\n1 2 3 6 8 9 10 13", "8\n1 2 3 6 8 9 10 13", "9\n1 2 3 8 9 10 13 15 16", "10\n1 2 3 8 9 10 13 15 16 17", "10\n1 2 3 8 9 10 13 15 16 17", "10\n1 2 3 8 9 10 13 15 16 17", "10\n1 2 3 6 9 10 11 17 19 20", "10\n1 2 3 6 9 10 11 17 19 20", "11\n1 2 3 10 11 12 15 17 18 19 22", "11\n1 2 3 6 10 13 15 17 20 22 23", "11\n1 2 3 6 9 11 13 18 19 22 24", "12\n1 2 5 8 10 12 17 18 21 23 24 25", "12\n1 2 3 6 9 11 13 18 19 22 24 26", "12\n1 2 3 6 9 11 13 18 19 22 24 26", "13\n1 2 3 12 13 14 19 20 21 24 26 27 28", "13\n1 2 3 6 8 9 13 17 19 24 26 28 29", "14\n1 3 4 5 14 15 16 21 22 23 26 28 29 30", "14\n1 3 4 5 14 15 16 21 22 23 26 28 29 30", "14\n1 2 3 6 8 15 17 19 24 25 28 30 31 32", "14\n1 2 3 6 8 11 19 23 24 25 28 30 32 33", "14\n1 2 3 6 8 10 11 19 23 25 30 32 33 34", "15\n1 2 3 6 9 18 19 20 26 27 28 31 33 34 35", "15\n1 2 3 6 8 17 19 24 25 26 29 31 32 33 36", "15\n1 2 3 6 8 9 17 19 24 26 27 31 32 36 37", "16\n1 2 5 6 7 10 21 22 23 29 30 31 34 36 37 38", "16\n1 2 3 6 8 10 13 21 25 29 30 31 34 36 38 39", "16\n1 2 3 6 8 9 17 19 24 27 29 31 32 36 37 40", "17\n1 2 3 6 9 10 17 19 22 27 29 30 34 35 38 40 41", "17\n1 2 3 6 8 10 21 23 25 30 31 32 35 37 38 39 42", "18\n1 3 4 5 8 12 19 21 23 24 29 32 35 36 37 40 42 43", "18\n1 2 5 7 8 9 12 21 24 27 29 31 36 37 38 41 43 44", "18\n1 2 5 6 7 18 20 21 22 25 28 32 36 37 38 41 43 45", "18\n1 2 3 6 9 11 19 22 24 26 32 33 36 37 38 41 43 46", "18\n1 2 3 6 8 9 10 13 29 30 31 38 39 40 43 45 46 47", "18\n1 2 3 6 8 9 10 13 17 29 32 34 36 41 42 43 46 48", "19\n1 2 3 6 8 9 13 24 26 28 29 34 38 40 41 42 45 48 49", "19\n1 2 3 6 8 9 10 13 29 30 31 38 39 40 43 45 46 47 50", "19\n1 2 3 6 8 9 10 13 17 29 32 34 41 42 43 46 48 50 51", "20\n1 2 6 7 8 11 23 25 26 27 36 37 38 43 44 45 48 50 51 52", "20\n1 2 3 6 8 9 24 26 27 28 37 38 39 44 45 46 49 51 52 53", "20\n1 2 3 6 8 9 10 13 17 30 32 34 40 41 44 46 48 51 53 54", "21\n1 2 3 6 8 9 13 26 28 29 30 39 40 41 46 47 48 51 53 54 55", "21\n1 2 3 6 8 9 10 13 29 30 31 40 41 42 47 48 49 52 54 55 56", "21\n1 2 3 6 8 9 10 13 29 30 31 40 41 42 47 48 49 52 54 55 56", "21\n1 2 3 6 8 9 10 13 29 30 31 34 39 41 46 47 48 51 53 54 58", "21\n1 2 3 6 8 9 10 13 17 29 30 34 38 40 43 50 51 55 57 58 59", "22\n1 2 3 6 8 9 10 13 29 30 31 34 36 43 45 47 52 53 56 58 59 60", "22\n1 2 3 6 8 9 10 13 29 30 31 34 36 43 45 47 52 53 56 58 59 60", "22\n1 2 3 6 8 9 10 13 17 29 30 34 38 41 43 50 51 52 57 58 59 62", "23\n1 2 7 8 9 12 14 15 16 33 35 36 37 47 48 49 54 55 56 59 61 62 63", "23\n1 2 3 6 8 9 10 27 29 30 31 34 41 43 45 46 51 54 57 58 59 62 64", "23\n1 2 3 6 8 9 10 13 29 32 34 36 39 46 47 48 51 54 55 56 62 64 65", "23\n1 2 3 6 8 9 10 13 17 29 30 34 36 38 43 51 52 55 58 59 60 65 66", "23\n1 2 3 6 8 9 10 13 17 29 30 34 36 38 43 51 52 55 58 59 60 65 66", "24\n1 2 3 6 8 9 10 13 29 30 31 34 38 43 47 49 50 51 57 58 62 63 66 68", "24\n1 2 3 6 8 9 10 13 17 32 36 38 40 41 46 53 54 55 60 61 64 65 68 69", "24\n1 2 3 6 8 9 10 13 17 32 36 38 40 41 46 53 54 55 60 61 64 65 68 69"] puts z[RD[]]

Problem B. Lots of Combinations.

We need to do two things: find (n,k) modulo 10**10, and check if (n,k) is greater than or equal to 10**10. The second part is relatively easy – if k <= n-k, then we can incrementally compute (n,1), (n,2) and stop as soon as we exceed 10**10. For the first part, we notice that it's enough to compute the answer modulo 2**10 and modulo 5**10, and then use the Chinese remainder theorem. Computing the answer modulo 5**10 is done by first calculating the power of 5 in (n,k) separately, and then calculating (n,k) with all powers of 5 removed from all numbers using the fact that we can now use division and thus just need to calculate factorials (skipping numbers divisible by 5) modulo 5**10, and numbers modulo 5**10 is a periodic sequence.

Problem C. Curiosity.

I’m pretty sure there are lots of different approaches that work in this problem. The two main directions I’m aware of is finding large blocks of data without unknowns and combining them together, or using various dynamic programming approaches that consider all possibilities. My solution is of the second kind: assume we’ve chosen the 6×6 field. We can then use dynamic programming to find the minimum possible number of contradictions in the input data (places where we know the color of some cell but it’s different from the actual cell we’re on). Now I use simulated annealing to find the 6×6 field that has zero contradictions. Of course, since all input files are given to you, you can do this without any time or memory limits and then just submit the discovered answers.

Problem D. Domination.

Since one of the dimensions is small (up to 10), we can do dynamic programming using a cut in that dimension as our state. More specifically, suppose we have filled first k columns and first p cells in the (k+1)-th column. Then we’re only interested what happens on the first p cells in the (k+1)-th column and the last (n-p) cells in the k-th column. Each cell can be in four states (has ‘1’, has ‘2’, has ‘0’ and doesn’t have an adjacent ‘2’, has ‘0’ and already has an adjacent ‘2’ (let’s call this state ‘3’)), yielding 4**10=2**20 states, but it turns out we don’t need all of them – some pairs of adjacent cell states are not useful: ’21’ and ’11’ can always be replaced by ’23’, and ’20’ is plain impossible. That brings the number of states down significantly, but the program is probably still too slow. The final touch is to notice that things become periodic if we fix n and increase m.

Problem E. Easy Learning.

This one probably has even more different solutions than C. There is a lot of theory for this kind of problem that I don’t want to recite here, my solution was using gradient boosting.

Problem F. Hash.

There are two main approaches here. One is called Pollard’s rho algorithm, and does not depend on the hash function much, the other actually uses the specific hash function we use. Consider values x_i = hash(‘1000 zeroes but i-th character is 1’) – hash(‘1000 zeroes’). Then we need to find two disjoint subsets of x_i with the same sum. Let’s do the following trick: sort all x_i, and take y_1=x_2-x_1, y_2=x_4-x_3, y_3=x_6-x_5, and so on. It’s not hard to see that now we have 500 numbers (2 times less), but the numbers themselves are about 1000 times less on average, and we still need to find two disjoint subsets with equal sums. Repeating this several times gets us numbers that are so small that two of them are bound to be equal. This problem has some very tricky cases when b=2 – you should watch out for those!

Problem G. RLE Size.

Here, you just need to carefully consider all cases. Each block of consecutive ‘?’ signs can be solved on paper, based on what’s to the left of it and what’s to the right, and then you can just implement the formulas you’ve discovered on paper in your program.

Problem H. Good Students and Bad Students.

This problem can be solved greedily. Let’s go from the highest numbers to the lowest numbers, and gradually fill all groups. Whenever we encounter a student that wants to be in the upper half, we place it in the first upper half that still has empty slots, if any. Whenever we encounter a student that wants to be in the lower half, we place it in the first lower half that has the corresponding upper half completely filled, if any, and in the first free upper half slot otherwise. The proof is a bit tricky but doable.

Problem I. Tennis Scores.

This was the classical ‘long statement, straightforward but long code’ problem. You just had to carefully calculate the probabilities of game outcomes for each player’s serve, then use those to calculate the probabilities of set outcomes, and then use those to calculate the probabilities of match outcomes. It’s important to notice that set outcomes depend on who’s serving first in the set.

Problem J. Three Squares.

This problem was supposed to be solved numerically. One step that you need to make to avoid falling into a trap is to realize that we’re not always rotating all three squares by the same angle, however improbable that might look. Here’s an example:

### External link:

http://codeforces.com/gym/100110

http://codeforces.com/blog/entry/5639