🕌

# AtCoder ABC201 個人的メモ

2021/05/16に公開

abc3完

## A - Tiny Arithmetic Sequence

Aの並び方を全て試した。

``````from itertools import permutations

A = list(map(int, input().split()))

for can in permutations(A):
if can[2] - can[1] == can[1] - can[0]:
print("Yes")
exit()
print("No")

``````

## B - Do you know the second highest mountainb

``````N = int(input())
mountains = []

for _ in range(N):
s, t = input().split()
mountains.append((int(t), s))

mountains.sort()
print(mountains[-2][1])

``````

## C - Secret Number

``````from itertools import product

S = input()

must = []
prohibit = []
for i, s in enumerate(S):
if s == "o":
must.append(i)
if s == "x":
prohibit.append(i)

ans = 0
for number in product(range(10), repeat=4):
if any(s in prohibit for s in number):
continue
if all(s in number for s in must):
ans += 1

print(ans)

``````

## D - Game in Momotetsu World

これの写経でac

``````def translate(s: str) -> int:
if s == "+":
return 1
else:
return -1

H, W = map(int, input().split())
A = [list(map(translate, input())) for _ in range(H)]
INF = 10 ** 18

# dp[i][j]は(i,j)のマスから最適な操作をしたときに
# 取り得る両者の差の最大値(青木くんの手番のマスでは最小値)
dp = [[-INF] * W for _ in range(H)]
dp[-1][-1] = 0

for i in range(H - 1, -1, -1):
for j in range(W - 1, -1, -1):
# A[y][x]<dp[y][x]であれば、dp=A-dpするたびにdpの正負が逆転する
# そのため、全てmax判定でもおｋ
if i < H - 1:
dp[i][j] = max(dp[i][j], A[i + 1][j] - dp[i + 1][j])
if j < W - 1:
dp[i][j] = max(dp[i][j], A[i][j + 1] - dp[i][j + 1])

if dp[0][0] > 0:
print("Takahashi")
elif dp[0][0] == 0:
print("Draw")
else:
print("Aoki")

``````

ログインするとコメントできます