- A
n*m/2. - B
Record the occurrences' number of each letters, signed as cnt[char].
For each char in string, get the cnt[c]^2 plus together, and this is the answer. - C
Calculate the Convex Hull.
The sum of the max value between x-difference and y-difference of each adjacent points in the convex hull's set and 4 is the answer.
4 step can make a circle of 360 degree. - D
Counting the answer with Half, and check the answer using Dynamic Programming.
Let dp[i][j] means the probability of first i objects where j of them exploded, and the transfering formular is:
dp[i][j] = P(i) * dp[i - 1][j - 1] + (1 - P(i)) * dp[i - 1][j], where P(i) means the i-th object exploding's probability.
problem E tutorial :
My AC code: https://codeforces.me/contest/50/submission/210541474
$$$b = -x$$$
$$$c = x^2 - y$$$
This first part of the solution can be done in $$$O(N)$$$ overall. Even binary search can be done to find $$$C$$$'s lower and upper limits for a fixed $$$B$$$. This takes $$$O(NlogN)$$$, which is also accepted.
The second part of the solution is to count all integer roots, which can be done in $$$O(N)$$$.
$$$r^2 + 2br + c = 0$$$
$$$-c = r^2 + 2br$$$
- On increasing b, we can see that RHS becomes more negative as $$$r$$$ is negative.
- It is enough to check only the first value of $$$b$$$ for which RHS becomes negative.
$$$r^2 + 2br < 0$$$
$$$2br < -r^2$$$
$$$2b > -r$$$
$$$ b > -r/2$$$
$$$ b = \lfloor (-r + 2)/2 \rfloor$$$