A17 - Dungeon 2
https://atcoder.jp/contests/tessoku-book/tasks/tessoku_book_q
提出
code: python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 0 1 2 3 4
# 2---4---1---3
# 5---3---3
dp = 0 * n
dp0 = 0
dp1 = a0
select = []
for i in range(2, n):
dpi = min(dpi-1 + ai-1, dpi-2 + bi-2)
if dpi-1 + ai-1 > dpi-2 + bi-2:
select.append("a")
else:
select.append("b")
print(dp)
print(select)
解答
code: python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 0 1 2 3 4
# 2---4---1---3
# 5---3---3
dp = 0 * (n)
dp0 = 0
dp1 = a0
for i in range(2, n):
dpi = min(dpi-1 + ai-1, dpi-2 + bi-2)
# print(dp)
# 0, 2, 5, 5, 8
# 答えの復元
# 変数 now は現在位置(ゴールから進んでいく)
# now: 4 → 3 → 1 → 0
ans = []
now = n-1
while True:
ans.append(now)
if now == 0:
break
# どこから部屋 now に向かうのが最適かを答え合わせ的に求める
if dpnow-1 + anow-1 == dpnow:
now = now - 1
# elif dpnow-2 + bnow-2 == dpnow:
# now = now - 2
else:
now = now - 2
ans.reverse()
ans2 = str(i+1) for i in ans
print(len(ans))
print(" ".join(ans2))
提出
code: python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 1 2 3 4 5
# 2 4 1 3
# 5 3 3
# どっち選んだか保存しておく
# dpi: i 時点の最小時間
dp = pow(10, 9) * (n+1)
dp1 = 0
dp2 = a0
selected = []
for i in range(3, n+1):
dpi = min(dpi-1+ai-2, dpi-2+bi-3)
if dpi-1+ai-2 < dpi-2+bi-3:
selected.append("a")
else:
selected.append("b")
# 'b', 'b', 'b'
# それぞれの時点で何選んだかでは再現できない