結果

問題 No.2423 Merge Stones
ユーザー dyktr_06dyktr_06
提出日時 2023-07-15 18:00:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,650 ms / 4,000 ms
コード長 878 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 78,300 KB
最終ジャッジ日時 2023-10-17 05:22:14
合計ジャッジ時間 90,289 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,256 KB
testcase_01 AC 55 ms
63,988 KB
testcase_02 AC 52 ms
61,972 KB
testcase_03 AC 49 ms
61,688 KB
testcase_04 AC 39 ms
53,372 KB
testcase_05 AC 49 ms
59,600 KB
testcase_06 AC 51 ms
63,900 KB
testcase_07 AC 47 ms
61,684 KB
testcase_08 AC 45 ms
59,600 KB
testcase_09 AC 39 ms
53,372 KB
testcase_10 AC 51 ms
61,972 KB
testcase_11 AC 2,268 ms
78,212 KB
testcase_12 AC 384 ms
77,992 KB
testcase_13 AC 1,118 ms
78,200 KB
testcase_14 AC 1,030 ms
78,192 KB
testcase_15 AC 942 ms
78,284 KB
testcase_16 AC 1,458 ms
78,280 KB
testcase_17 AC 1,018 ms
78,208 KB
testcase_18 AC 1,503 ms
78,280 KB
testcase_19 AC 377 ms
77,996 KB
testcase_20 AC 1,020 ms
78,192 KB
testcase_21 AC 1,091 ms
78,200 KB
testcase_22 AC 1,024 ms
78,192 KB
testcase_23 AC 950 ms
78,284 KB
testcase_24 AC 956 ms
78,284 KB
testcase_25 AC 961 ms
78,284 KB
testcase_26 AC 958 ms
78,284 KB
testcase_27 AC 1,248 ms
78,284 KB
testcase_28 AC 1,695 ms
78,204 KB
testcase_29 AC 1,412 ms
78,280 KB
testcase_30 AC 1,039 ms
78,208 KB
testcase_31 AC 1,040 ms
78,208 KB
testcase_32 AC 1,107 ms
78,200 KB
testcase_33 AC 947 ms
78,284 KB
testcase_34 AC 1,416 ms
78,264 KB
testcase_35 AC 1,034 ms
78,192 KB
testcase_36 AC 1,046 ms
78,192 KB
testcase_37 AC 945 ms
78,284 KB
testcase_38 AC 956 ms
78,284 KB
testcase_39 AC 1,095 ms
78,200 KB
testcase_40 AC 1,571 ms
78,288 KB
testcase_41 AC 1,414 ms
78,288 KB
testcase_42 AC 1,082 ms
78,200 KB
testcase_43 AC 377 ms
77,996 KB
testcase_44 AC 1,087 ms
78,200 KB
testcase_45 AC 955 ms
78,284 KB
testcase_46 AC 1,229 ms
78,284 KB
testcase_47 AC 992 ms
78,264 KB
testcase_48 AC 933 ms
78,284 KB
testcase_49 AC 379 ms
77,992 KB
testcase_50 AC 382 ms
77,992 KB
testcase_51 AC 2,012 ms
78,276 KB
testcase_52 AC 2,463 ms
78,300 KB
testcase_53 AC 2,330 ms
78,212 KB
testcase_54 AC 2,032 ms
78,284 KB
testcase_55 AC 2,650 ms
78,208 KB
testcase_56 AC 1,495 ms
78,296 KB
testcase_57 AC 1,458 ms
78,296 KB
testcase_58 AC 1,695 ms
78,216 KB
testcase_59 AC 1,146 ms
78,204 KB
testcase_60 AC 1,407 ms
78,288 KB
testcase_61 AC 2,221 ms
78,212 KB
testcase_62 AC 2,222 ms
78,212 KB
testcase_63 AC 2,210 ms
78,220 KB
testcase_64 AC 2,215 ms
78,212 KB
testcase_65 AC 2,220 ms
78,212 KB
testcase_66 AC 2,214 ms
78,220 KB
testcase_67 AC 2,222 ms
78,212 KB
testcase_68 AC 2,203 ms
78,212 KB
testcase_69 AC 2,195 ms
78,168 KB
testcase_70 AC 2,204 ms
78,220 KB
testcase_71 AC 2,098 ms
78,220 KB
testcase_72 AC 2,092 ms
78,220 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]
      bitlr = dp[l][r]
      for p in range(k + 1):
        if dp[l][m] == 0 or dp[m + 1][r] == 0:
          continue
        bitlr |= ((bitl << p) & bitr)
        bitlr |= ((bitl >> p) & bitr)
        bitlr |= (bitl & (bitr << p))
        bitlr |= (bitl & (bitr >> p))
      dp[l][r] = bitlr

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