Codeforces Round #723 ABCDE Solutions (Java/C++)

A. Mean Inequality

Solution:

Sort the array. And split the array to two parts. Each time, we take one number from each of the two parts at a time.

Code:

Java

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

C++

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

B. I Hate 1111

Solution:

Consider 1111, we found that $1111=11\times 101$. In same way, we only need consider if the number can be built by 11 and 111.

Let $x=a\cdot 11 + b\cdot 111$. when $b>11$, $x=a\cdot 11 + 11 \cdot 111 + (b-11)\cdot 111=(a+111)\cdot 11 + (b-11) \cdot 111$. So, if there is a solution, then we must can find the solution which $b<11$. So, just enumerate the b.

Code:

Java

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

C++

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

C. Potions

Tried to find some $n^2$ solution, so that can pass easy version only. But I cannot find that.
And for this problem, it is obviously, just calculating the prefix sum. When the sum is less than 0, we spit the worst potion.

Codeforces Round #723 Potions (Hard/Easy) Solution (Java/C++)
Solution:First, if there are not any limitations, we will drink all the potions. In fact, the only limitation is the health must not less than 0.
Click the link above for detail solution

D. Kill Anton

The conclusion is: in the answer, the four letters must be consecutive. So just enumerate the permutation of four letters and see which one can make largest cost.

Codeforces Round #723 Kill Anton Solution (Java/C++)
Solution:Let consider how Anton fix the DNS. We found that: for minimum cost, every time, Anton just fixing one character. For example, fix NNOTA to ANTON.
Click the link above for detail solution

E. Oolimry and Suffix Array

After I build the 4th sample data, then this problem is solved. The point is: find out the way to handle the case which string have duplicate character.

Codeforces Round #723 Oolimry and Suffix Array Solution (Java/C++)
Solution:Let us represent the string to c.First, we can notice that: for i<j, there must be $c_{s[i]}\leq c_{s[j]}$. For example, $[3,2,4,1,0,5,6]$, at least we have $c_3\leq c_2\leq c_4\leq c_1\leq c_0\leq c_5\leq c_6$.
Click the link above for detail solution
Show Comments
DigitalOcean Referral Badge