結果

問題 No.2656 XOR Slimes
ユーザー dp_ijk
提出日時 2024-06-22 16:34:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 82,712 KB
実行使用メモリ 78,332 KB
最終ジャッジ日時 2024-06-22 16:34:22
合計ジャッジ時間 16,380 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate

INF = float("INF")
N = int(input())
X = list(map(int, input().split()))
A = list(map(int, input().split()))
wA = list(accumulate(A, func=lambda a, b: a^b, initial=0))

dp = [INF] * (N+1)
dp[N] = 0
for i in range(N-1, -1, -1):
   cands = []
   for j in range(i+1, N+1):
      S = wA[j]^wA[i]
      score = S + dp[j]
      score += X[j-1] - X[i]
      cands.append(score)
   dp[i] = min(cands)

ans = dp[0]
print(ans)
0