AtCoder Beginner Contest 143

Updated:

AtCoder Beginner Contest 143

Solutions

A - Curtain

Flush $\max(0, A - 2B)$.

B - TAKOYAKI FESTIVAL 2019

Solution in $O(N)$-time

This problem can be solved in $O(N)$-time. Let \begin{align} S &= \sum _ {i \in N} A _ i, \\ T &= \sum _ {i \in N} A _ i ^ 2. \end{align} The answer is $(S ^ 2 - T) / 2$.

C - Slimes

Solution

Execute the following code.

  int ans{0};
char x{'D'};
for (auto i = 0; i < N; ++i)
{
if (x != S[i])
{
++ans;
x = S[i];
}
}
cout << ans << endl;


This is just the run-length compression.

D - Triangles

Solution

Try all $x$ and $y$. The candidate of $z$ is such that $\lvert x - y \rvert < z < x + y.$ We can count such $z$ by cumulated sum or segment tree. Be careful that we have to exclude $x$ and $y$ and we have to divide the answer by $3$.

Tags:

Categories: