ABC181 - Atcoder/Python精進のための解説メモ
2022/12/27
ABC181 - A.Heavy Rotation
AtCoder公式 | ABC181 - A.Heavy Rotation解答
n = int(input())
print('White' if n % 2 == 0 else 'Black')
要点解説メモ
- やるだけ
ABC181 - B.Trapezoid Sum
AtCoder公式 | ABC181 - B.Trapezoid Sum解答
n = int(input())
ans = 0
for _ in range(n):
a, b = map(int, input().split())
ans += (b - a + 1) * (a + b) // 2
print(ans)
要点解説メモ
- sumとか使うと時間足りない
ABC181 - C.Collinearity
AtCoder公式 | ABC181 - C.Collinearity解答
n = int(input())
x = []
y = []
ans = 'No'
for _ in range(n):
xi, yi = map(int, input().split())
x.append(xi)
y.append(yi)
for i in range(n):
for j in range(i + 1, n):
for k in range(j + 1, n):
x1 = x[i] - x[j]
y1 = y[i] - y[j]
x2 = x[j] - x[k]
y2 = y[j] - y[k]
if x1 * y2 == x2 * y1:
ans = 'Yes'
print(ans)
要点解説メモ
- やるだけ
- 一次関数の傾きを知らないとしんどいかも
- ベクトルでもできそうだけど傾きのほうが計算シンプルな気が
ABC181 - D.Hachi
AtCoder公式 | ABC181 - D.Hachi解答
from itertools import accumulate
n = int(input())
aaa = list(map(int, input().split()))
ans = 0
x = 0
acc = list(accumulate(aaa))
acc_max = list(accumulate(acc, func=max))
for i in range(n):
ans = max(ans, x + acc_max[i])
x += acc[i]
print(ans)