Codeforces Round 633 Div2
Problems on Codeforces are generally harder than ordinary interview problems. If your goal is only interviews, practicing LeetCode is enough. But if you are interested in algorithms and competitive programming, I strongly encourage you to give it a try. The quantity and quality of the problems far exceed LeetCode. It also provides different tracks for students at different levels, with different problem difficulties. For high-level players, the contest experience is much better.
So far I have participated in two Div.2 contests, and my rating is 1480. Yes, the initial rating is 1500, and I actually dropped.
A. Filling Diamonds
We can think about this problem with dynamic programming. For a belt of length n, there are two states:
0.
/
and
1.
/
\
The state transition equations are:
dp[n][0] = dp[n-1][1] + dp[n-1][0],
dp[n][1] = dp[n-1][1].
Initial values:
dp[0][1] = 1,
dp[0][0] = 0.
The answer is dp[n][0].
From this equation, we can quickly derive dp[n][0] = n.
Time complexity: O(1),
Space complexity: O(1).
1 |
|
The problem setter also proudly said that this was the simplest Div.2 A so far. The code is very simple, but the idea is still quite clever.
B. Sorted Adjacent Differences
Greedy. Sort first, then start selecting from the middle: jump right once, then jump left once.
Time complexity: O(n log n),
Space complexity: O(n).
1 |
|
C. Powered Addition
The problem can be transformed into this: we can add at most 2^k - 1 to any number in the array to make the whole array non-decreasing. Find the minimum k.
Time complexity: O(N),
Space complexity: O(N).
1 |
|