ABC176 - Atcoder/Python精進のための解説メモ
2022/12/27
ABC176 - A.Takoyaki
AtCoder公式 | ABC176 - A.Takoyaki解答
n, x, t = map(int, input().split())
print(-(-n // x) * t)
別解
import math
n, x, t = map(int, input().split())
print(math.ceil(n / x) * t)
別解
n, x, t = map(int, input().split())
print(n // x * t if n % x == 0 else (n // x + 1) * t)
要点解説メモ
- 繰り上げの計算方法は色々知っておくと良さそう
ABC176 - B.Multiple of 9
AtCoder公式 | ABC176 - B.Multiple of 9解答
n = list(map(int, input().split()))
print('Yes' if sum(n) % 9 == 0 else 'No')
要点解説メモ
- 入力を受け取る段階で分割しておくのが早そう
ABC176 - C.Step
AtCoder公式 | ABC176 - C.Step解答
n = int(input())
aaa = list(map(int, input().split()))
ans = 0
for i in range(1, n):
diff = aaa[i] - aaa[i - 1]
if diff < 0:
aaa[i] -= diff
ans -= diff
print(ans)
要点解説メモ
- 左から順に単純増加かつ、隣り合うA同士について考えるだけで良いので、シンプル実装して間に合う
ABC176 - D.Wizard in Maze
AtCoder公式 | ABC176 - D.Wizard in Maze解答
from collections import deque
h, w = map(int, input().split())
ch, cw = map(lambda x: int(x) + 1, input().split())
dh, dw = map(lambda x: int(x) + 1, input().split())
s = [["#"] * (w + 4) for _ in range(2)] + [["#"] * 2 + list(input()) + ["#"] * 2 for _ in range(h)] + [
["#"] * (w + 4) for _ in range(2)]
m1 = ((-1, 0), (0, -1), (0, 1), (1, 0))
m2 = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if abs(i) + abs(j) > 1]
a = deque([(ch, cw)])
b = deque()
i = 0
while a:
while a:
ah, aw = a.popleft()
if s[ah][aw] != ".":
continue
b.append((ah, aw))
s[ah][aw] = i
for bh, bw in m1:
bh, bw = ah + bh, aw + bw
if s[bh][bw] == ".":
a.append((bh, bw))
while b:
ah, aw = b.popleft()
for bh, bw in m2:
bh, bw = ah + bh, aw + bw
if s[bh][bw] == ".":
a.append((bh, bw))
i += 1
ans = s[dh][dw]
print(ans if ans != "." else -1)
要点解説メモ
- どなたかのACの写経からはじめた
- 01BFSの典型だと気づくために、慣れておく
- 何度も見返しておきたい
- PyPy3じゃないと通らないかも