Codeforces Educational Codeforces Round 151
Contest link
Official editorial
I solved the first two problems and got stuck on the third.
Rating change: 1407 -> 1378
A. Forbidden Integer
Case analysis. If 1 can be chosen, then any number can definitely be formed.
If not, but 2 and 3 can be chosen, then any number except 1 can also be formed.
If only 2 can be chosen, then only even numbers can be formed.
Time complexity: O(t * n),
1 | t = int(input()) |
B. Come Together
Case analysis. B and C are in different quadrants, so the longest shared route differs.
Time complexity: O(t),
Space complexity: O(1).
1 | t = int(input()) |
C. Strong Password
The brute-force method is simple: backtrack to enumerate all passwords satisfying the l and r constraints, then check whether each is a subsequence of s.
However, the time complexity of the backtracking step is already exponential.
The correct solution is greedy. For each position, choose the digit that appears as far to the right as possible in s.
Time complexity: O(m*D + n), n = s.length, D = r_i - l_i = 10