Codeforces 418 Div2
A An abandoned sentiment from past
1 | int n,k; |
B An express train to reveries
Given two sequences $(n<1000)$, find a sequence that differs from each of them in exactly one element.
1 | int n; |
C An impassioned circulation of affection
Given a string of length $n<1500$ and $q<200000$ queries $(m_i,c_i)$, each query allows changing $m_i$ characters. Find the longest contiguous segment of character $c_i$.
Since $n * q$ is around $10^8$, there is a brute-force solution.
I used preprocessing plus DP and spent a long time debugging it. So silly.
1 | int n; |
In fact, preprocessing can be done directly as follows.
1 | scanf("%d%s", &n, s + 1); |
D An overnight dance in discotheque
Divide $n$ circles into two groups. If a circle is contained an even number of times within a group, subtract its area. Find the maximum total area.
Apply greediness starting with the circle of greatest area.
1 | int n; |
E An unavoidable detour for home
Given $n<50$ vertices with prescribed degrees of 2 or 3, construct a tree rooted at 1 such that:
Every vertex’s shortest distance $len_i$ from 1 is fixed, and that path is unique.
For $i>2$, $len_i > len_{i-1}$.
Because every vertex’s distance to the root is fixed and unique, enumerate possibilities by level.
dp[a][b][c][d] represents a state in which the previous level has a vertices with one free edge and b with two, while this level has c with one free edge and d with two. The rest is state transition.
1 | int n; |