結果

問題 No.2423 Merge Stones
ユーザー dyktr_06dyktr_06
提出日時 2023-07-15 17:54:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,290 ms / 4,000 ms
コード長 848 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 81,524 KB
実行使用メモリ 78,520 KB
最終ジャッジ日時 2023-10-17 05:20:13
合計ジャッジ時間 93,433 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,372 KB
testcase_01 AC 54 ms
64,084 KB
testcase_02 AC 51 ms
64,064 KB
testcase_03 AC 48 ms
61,716 KB
testcase_04 AC 40 ms
53,372 KB
testcase_05 AC 44 ms
59,620 KB
testcase_06 AC 50 ms
61,876 KB
testcase_07 AC 46 ms
61,648 KB
testcase_08 AC 45 ms
59,620 KB
testcase_09 AC 40 ms
53,372 KB
testcase_10 AC 51 ms
62,016 KB
testcase_11 AC 2,560 ms
78,324 KB
testcase_12 AC 290 ms
78,024 KB
testcase_13 AC 984 ms
78,280 KB
testcase_14 AC 929 ms
78,244 KB
testcase_15 AC 860 ms
78,340 KB
testcase_16 AC 1,366 ms
78,372 KB
testcase_17 AC 928 ms
78,268 KB
testcase_18 AC 1,366 ms
78,368 KB
testcase_19 AC 291 ms
78,020 KB
testcase_20 AC 921 ms
78,244 KB
testcase_21 AC 970 ms
78,284 KB
testcase_22 AC 918 ms
78,244 KB
testcase_23 AC 841 ms
78,340 KB
testcase_24 AC 845 ms
78,340 KB
testcase_25 AC 847 ms
78,340 KB
testcase_26 AC 853 ms
78,340 KB
testcase_27 AC 1,158 ms
78,372 KB
testcase_28 AC 1,549 ms
78,288 KB
testcase_29 AC 1,332 ms
78,368 KB
testcase_30 AC 921 ms
78,264 KB
testcase_31 AC 929 ms
78,268 KB
testcase_32 AC 993 ms
78,280 KB
testcase_33 AC 854 ms
78,340 KB
testcase_34 AC 1,205 ms
78,344 KB
testcase_35 AC 921 ms
78,244 KB
testcase_36 AC 917 ms
78,244 KB
testcase_37 AC 844 ms
78,340 KB
testcase_38 AC 848 ms
78,340 KB
testcase_39 AC 1,011 ms
78,284 KB
testcase_40 AC 1,396 ms
78,380 KB
testcase_41 AC 1,241 ms
78,368 KB
testcase_42 AC 991 ms
78,284 KB
testcase_43 AC 292 ms
78,020 KB
testcase_44 AC 994 ms
78,280 KB
testcase_45 AC 846 ms
78,340 KB
testcase_46 AC 1,197 ms
78,392 KB
testcase_47 AC 846 ms
78,340 KB
testcase_48 AC 857 ms
78,340 KB
testcase_49 AC 293 ms
78,024 KB
testcase_50 AC 292 ms
78,020 KB
testcase_51 AC 2,192 ms
78,376 KB
testcase_52 AC 2,696 ms
78,520 KB
testcase_53 AC 2,543 ms
78,288 KB
testcase_54 AC 2,184 ms
78,376 KB
testcase_55 AC 3,024 ms
78,280 KB
testcase_56 AC 1,404 ms
78,380 KB
testcase_57 AC 1,365 ms
78,376 KB
testcase_58 AC 1,594 ms
78,300 KB
testcase_59 AC 1,029 ms
78,280 KB
testcase_60 AC 1,343 ms
78,376 KB
testcase_61 AC 2,547 ms
78,324 KB
testcase_62 AC 2,551 ms
78,288 KB
testcase_63 AC 2,514 ms
78,324 KB
testcase_64 AC 2,540 ms
78,288 KB
testcase_65 AC 2,534 ms
78,324 KB
testcase_66 AC 2,863 ms
78,324 KB
testcase_67 AC 3,290 ms
78,324 KB
testcase_68 AC 2,631 ms
78,292 KB
testcase_69 AC 2,551 ms
78,268 KB
testcase_70 AC 2,447 ms
78,324 KB
testcase_71 AC 2,207 ms
78,320 KB
testcase_72 AC 2,212 ms
78,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
a = list(map(int, input().split()))
c = list(map(lambda x: int(x)-1, input().split()))
dp = [[0] * 2 * n for _ in range(2 * n)]
for i in range(n):
  dp[i][i] = 1 << c[i]
  dp[i + n][i + n] = 1 << c[i]

for len in range(2, n + 1):
  for l in range(2 * n - len + 1):
    r = l + len - 1
    for i in range(len - 1):
      m = l + i
      bitl, bitr = dp[l][m], dp[m + 1][r]
      for p in range(k + 1):
        if dp[l][m] == 0 or dp[m + 1][r] == 0:
          continue
        dp[l][r] |= ((bitl << p) & bitr)
        dp[l][r] |= ((bitl >> p) & bitr)
        dp[l][r] |= (bitl & (bitr << p))
        dp[l][r] |= (bitl & (bitr >> p))

s = [0]
for i in range(2 * n):
  s.append(s[i] + a[i % n])
ans = 0
for i in range(2 * n):
  for j in range(i, 2 * n):
    if dp[i][j]:
      ans = max(ans, s[j + 1] - s[i])
print(ans)
0