cdschenshuai's blog

By cdschenshuai, 11 years ago, In English

It's a post recording problems that I think is helpful to MY problem solving ability.
Caution: May NOT fit your appetite!
2B - Наименее круглый путь
3D - Скобочная последовательность
Chinese solution
5C - Наибольшая правильная скобочная подстрока
7B - Менеджер памяти
7D - Палиндромность
Finding longest palindromic substring using Manacher's algorithm in O(n)
9D - Сколько деревьев?
dp[i][j]: i nodes with height less than j, dp[i][j] = sum{dp[k][j-1] * dp[i-k-1][j-1]}(Choosing number k+1 as the root node)
12D - Бал
Binary Indexed Tree. A 2D version can be found here
13C - Последовательность
13E - Лунки
Divide array with length n into sqrt(n) consecutive blocks
14D - Два пути
Very good problem, reference
14E - Верблюды
reference
16E - Рыбы
Conditional probability
18D - Продавец Вася
recommended solution 253348
18E - Флаг 2
dp[level][colorA][colorB], so dp[level[i][j] = change + min(dp[level-1][ii][jj] (i != ii && j != jj), where change means differences between original level-th row and new 'ijijiji...ijij..' row. Time complexity is O(n*26*26*(m+26*26))
19B - Кассир
Tricky 0-1 knapsack problem.

  • Vote: I like it
  • -17
  • Vote: I do not like it

»
11 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you so much for your recommendation, I'll have a try later

»
11 years ago, # |
Rev. 2   Vote: I like it +13 Vote: I do not like it

"Snow White and N dwarves" (Russian Code Cup 2013 Final, problem B)

Snow White has N friend dwarves numbered from 1 to N. The height of i-th dwarf is hi; 1 ≤ hi ≤ N

Princess calls any nonempty subset s1... sm of these dwarves sympathetic if the following condition holds:

There are T test cases, each contains N — the number of dwarves and N integers hi — heights. For each test case, you have to print any sympathetic subset in the same format, or -1 if there is no solution.

Total N does not exceed 106

Time limit 2s, memory limit 256Mb

Example:

Input

1
5
3 4 1 2 2

Output

4
1 2 3 4

140Mb archive containing all tests, checkers, author solutions, etc: here (folder "equality")