Codeforces Round #741 ABCD Solutions (Java/C++)

A. The Miracle and the Sleeper

Solution:

Obviously, when b=r/2+1, the value of a%b is the largest. Of course, note that the value of b cannot be less than l.

Code:

Java

Submission #127456331 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #127456424 - Codeforces
Codeforces. Programming competitions and contests, programming community

B. Scenes From a Memory

Although the conclusion is very simple, it is enough to directly enumerate all the possibilities within three digits by brute force. But the proof of this conclusion is still interesting.

Codeforces Round #741 Scenes From a Memory Solution (Java/C++)
Solution:First of all, it is obvious that if the 1, 4, 6, 8, 9 appear in the original number. All other numbers can be deleted, and only one digit is left.
Click the link above for detail solution

C. Rings

Solution:

First, if the original string is all 1s. It's very simple, just choose any two substrings of length n/2. At this time k=1.

If there is 0 in the original string, then we can let one of t and s contain this 0, and the other does not contain this 0 based on the position of 0.

Code:

Java

Submission #127539856 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #127539958 - Codeforces
Codeforces. Programming competitions and contests, programming community

D. Two Hundred Twenty One (Easy/Hard)

The main thing to find this conclusion: when the interval length is odd, you only need to delete one to make the sum of interval to 0. After figured out this conclusion, the rest is very simple.

Codeforces Round #741 Two Hundred Twenty One Solution (Java/C++)
Solution:First, we define $b[i]=a[i]\cdot (-1)^{(i-1)}$, $sum(l,r)=\sum_{i=l}^r{b[ i]}$.So for any i, b[i] is either 1 or -1. Therefore, if the final sum is 0, then there must be the same number of 1 as the number of -1.
Click the link above for detail solution
Show Comments
DigitalOcean Referral Badge