RussianCodeCup's blog

By RussianCodeCup, 9 years ago, translation, In English

A. Secret Code

All you have to do is just implement the required counting. Identifying correct characters at correct positions is absolutely straightforward. Identifying correct characters at incorrect positions can be, for example, implemented using used[c] array with true values for characters in the secret code and false for other characters.

B. Chaos

Consider two maximal numbers of the initial array. The maximal possible value that can be obtained is their average value.

To prove this, you can see Doc's moves as removing one number from the board and replacing two other numbers with two copies of their average value. So the average value of two maximal numbers never increases.

The following strategy allows to get such value in the end: each move remove the minimal number and replace two maximal numbers with two copies of their average values. Starting from the second move the two maximal numbers will be the same and equal to the answer.

C. New Adventure of Marty and Doc

You have to minimize the sum Sum(i = 1..n, j = 1..m, 2·ai, j·(|i - x| + |j - y| + 1)). First notice that no term depends on both coordinates, so the sum can be divided to three sums: Sum(2·ai, j), Sum(2·ai, j·|i - x|) and Sum(2·ai, j·|j - y|).

The first sum is constant for the given input, so we need to minimize the second and the third sum which can be done independently by choosing the row and the column. Consider the second sum, it can be proved that the optimal value is achieved if we take r equal to the median of Sum(j = 1..m, a1, j) times 1, Sum(j = 1..m, a2, j) times 2, ..., Sum(j = 1..m, an, j) times n.

Column can be found using the same idea.

D. Teams Creation

Let's use dynamic programming.

Sort all skill levels, and for each value find the number of students with such skill level. Note that if the team contains students with skill levels l and r, all students with skill levels m such that l < m < r will also be in the same team. So let us calculate the value dp[i][j][f] — the number of ways to create j teams of students with skill levels up to i, the last team can (f = true) or cannot (f = false) have more students. To make a transition we need additional value f[k][g] counts the number of ways to create g teams of k students that have the same skill level. Let there be k students with skill level i + 1, we iterate over g from 1 to k and relax dp[i + 1][j'][f'] using f[k][g]. Note that this takes O(nk) because the total number of g attempted for each j is equal to n.

To find f[k][g] we consider the k-th student. He is either in the team on his own (f[k - 1][g - 1]) or in one of the other teams (f[k - 1][gg).

Both arrays are calculated in time O(nk), so the time complexity is O(nk).

E. Maximal Sum

Let us sort bj in decreasing order. Add values to array a in decreasing order as well until all numbers greater or equal to the current bj is added. Now the array contains only numbers ai ≥ bj. After adding the new ai use interval tree to find the maximal sum subsegment at the segment (see discussion here, for example, to learn how to do this using interval tree: http://codeforces.me/blog/entry/17780).

  • Vote: I like it
  • +31
  • Vote: I do not like it

»
8 years ago, # |
Rev. 4   Vote: I like it +3 Vote: I do not like it

In Problem C , "it can be proved that the optimal value is achieved if we take r equal to the median of Sum(j = 1..m, a1, j) times 1, Sum(j = 1..m, a2, j) times 2, ..., Sum(j = 1..m, an, j) times n."

In case ,anyone wants the task Here It is How can it be proved ??? Can someone please explain ???