A - Large Digits
Return max of S(A) and S(B).
1 |
|
B - Gentle Pairs
Return the number of points whose slope is between -1 and 1.
1 |
|
C - 1-SAT
Return the unsatifiable string.
1 |
|
D - Choose Me
Choose the minimum number of speeches to make to win-over another candidate.
Use greedy method.
1 |
|
E - Through Path
There are N vertices and N-1 edges. Each edge connects ai and bi.
Perform the following 2 operations.
- add x to all descendants of ai without traversing bi;
- add x to all descendants of bi without traversing ai;
Print the value of each node at the end.
Solution1:
For operation 1, add x to global root and -x to vertex b;
For operation 2, add x to vertex b;
In order to propagate the change to its subtree, need to preprocess depths of each vertex.
1 |
|
Solution2:
Solution1 doesn’t support online query and arbitrary range change between nodes.
For arbitrary range, use dfs order;
For online query, use segment tree.
1 |
|
F - Close Group
Given a graph of N nodes and M edges. A satisfied connected component is one where each pair of nodes within it are directly connected.
Can remove zero or more edges on the graph.
Return the minimum number of satisfied connected components.
Idea: For each set S, which is a subset of V, calculate dp[S] from its subset, using dynamic programming.
specifically, dp[S] = min(dp[T] + dp[S\T]), for all S’s subsets.
if {T} satisfies, the dp[T] = 1.
The satisfying condition can be pre-processed using O(2^N * N^2);
The transition takes O(3^N) time.
Time complexity: O(2^N * N^2 + 3^N).
1 |
|