Codeforces Round #358 (Div. 2) Editorial

Правка en10, от halin.george, 2016-06-18 13:46:51

682A — Alyona and Numbers

Let's iterate over the first number of the pair, let it be x. Then we need to count numbers from 1 to m with the remainder of dividing 5 equal to (5 - xmod5)mod 5. For example, you can precalc how many numbers from 1 to m with every remainder between 0 and 4.

682B — Alyona and Mex

Let's sort the array. Let cur =  1. Then walk through the array. Let's look at current number. If it is greater or equal to cur, then let's increase cur by 1. Answer is cur.

682C — Alyona and the Tree

Let's do dfs. Suppose that we now stand at the vertex u. Let v be some ancestor of vertex u. Then dist(v, u) = dist(1, u) - dist(1, v). If dist(v, u) > au, then the vertex u makes v sad. So you must remove the whole subtree of vertex u. Accordingly, it is possible to maintain a minimum among dist(1, v) in dfs, where v is ancestor of u (vertex, in which we now stand). And if the difference between the dist(1, u) and that minimum is greater than au, then remove au with the whole subtree.

682D — Alyona and Strings

Let's use the method of dynamic programming. Let d[i][j][cnt][end] be answer to the problem for the prefix of string s of length i and for the prefix of string t of length j, we have chosen cnt substrings. end = 1, if both last characters of the prefixes are included in the maximum subsequence and end = 0 otherwise.

When the state is d[i][j][cnt][end], you can add the following letters in the string s or t, though it will not be included in the response subsequence. Then d[i + 1][j][cnt][0] = max(d[i + 1][j][cnt][0], d[i][j][cnt][end]), d[i][j + 1][cnt][0] = max(d[i][j + 1][cnt][0], d[i][j][cnt][end]). So the new value of end is 0, because the new letter is not included in the response subsequence.

If s[i] = t[j], then if end = 1, we can update the d[i + 1][j + 1][k][1] = max(d[i][j][k][end] + 1, d[i + 1][j + 1][k][1]). When we add an element to the response subsequence, the number of substring, which it is composed, will remain the same, because end = 1. If end = 0, we can update d[i + 1][j + 1][k + 1][1] = max(d[i][j][k][end] + 1, d[i + 1][j + 1][k + 1][1]). In this case, the new characters, which we try to add to the response subsequence, will form a new substring, so in this case we do the transition from the state k to the state k + 1.

The answer will be the largest number among the states of the d[n][m][k][end], where the values ​​of k and end take all possible values.

682E — Alyona and Triangles

Let's find the triangle with maximum area among ​​all triangles whose vertices belong to the set of points. (For N2 with the convex hull and the two pointers). We can prove that if we take the triangle, whose vertices are the midpoints of the sides of the triangle with maximum area, the area of ​​such a triangle is not greater than 4S, and it contains all the points of the set. Let us assume that there is a point lying outside the triangle-response. Then we can get longer height to some side of triangle, so we have chosen a triangle with not maximum area(contradiction).

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en11 Английский halin.george 2016-06-18 13:47:05 0 (published)
en10 Английский halin.george 2016-06-18 13:46:51 821
en9 Английский halin.george 2016-06-18 13:46:04 75
en8 Английский halin.george 2016-06-18 13:43:14 462
en7 Английский halin.george 2016-06-18 13:40:00 451
en6 Английский halin.george 2016-06-18 13:37:37 1485
en5 Английский halin.george 2016-06-18 13:31:50 1013
en4 Английский halin.george 2016-06-18 13:22:26 687
en3 Английский halin.george 2016-06-18 13:15:54 189
en2 Английский halin.george 2016-06-18 13:15:31 3663 Tiny change: 'ou can predposchitat how many ' - (saved to drafts)
ru5 Русский halin.george 2016-06-18 12:42:20 5 Мелкая правка: 'i][j][cnt]). То ест' -> 'i][j][cnt][end]). То ест'
en1 Английский halin.george 2016-06-17 23:57:38 77 Initial revision for English translation
ru4 Русский halin.george 2016-06-17 23:42:10 2256 Мелкая правка: '(v, u) (опубликовано)
ru3 Русский halin.george 2016-06-17 23:35:43 865
ru2 Русский halin.george 2016-06-17 23:31:02 8 Мелкая правка: ' равным $(4 - x mod 5)$. Наприме' -
ru1 Русский halin.george 2016-06-17 23:28:39 371 Первая редакция (сохранено в черновиках)