ABC245 C - Choose Elements
https://atcoder.jp/contests/abc245/tasks/abc245_c
提出
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 全探索は計算量オーバー
for i in range(n-1):
if (abs(ai - ai+1) > k and abs(ai - bi+1) > k and abs(bi - bi+1) > k and abs(bi - ai+1) > k):
print('No')
exit()
print('Yes')
解答
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0,0)
b.insert(0,0)
dp = False for _ in range(n+1) # (X1, X2...Xi)まで考慮したとき、Xi = Aiとしてよいか
ep = False for _ in range(n+1) # (X1, X2...Xi)まで考慮したとき、Xi = Biとしてよいか
dp1 = True
ep1 = True
for i in range(2, n+1):
if (dpi-1):
if(abs(ai-1 - ai) <= k):
dpi = True
if(abs(ai-1 - bi)<=k):
epi = True
if(epi-1):
if(abs(bi-1 - ai) <= k):
dpi = True
if(abs(bi-1 - bi)<=k):
epi = True
if(dpn or epn):
print("Yes")
else:
print("No")
テーマ
#dp
メモ
https://atcoder.jp/contests/abc245/editorial/3634