結果

問題 No.2423 Merge Stones
ユーザー dyktr_06dyktr_06
提出日時 2023-07-15 17:41:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,352 ms / 4,000 ms
コード長 788 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 81,764 KB
実行使用メモリ 78,540 KB
最終ジャッジ日時 2023-10-17 03:58:48
合計ジャッジ時間 152,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,528 KB
testcase_01 AC 48 ms
64,272 KB
testcase_02 AC 49 ms
64,276 KB
testcase_03 AC 45 ms
62,204 KB
testcase_04 AC 35 ms
53,528 KB
testcase_05 AC 47 ms
62,172 KB
testcase_06 AC 51 ms
64,272 KB
testcase_07 AC 49 ms
62,208 KB
testcase_08 AC 47 ms
62,172 KB
testcase_09 AC 36 ms
53,528 KB
testcase_10 AC 48 ms
64,276 KB
testcase_11 AC 3,188 ms
78,488 KB
testcase_12 AC 587 ms
78,392 KB
testcase_13 AC 3,149 ms
78,472 KB
testcase_14 AC 2,010 ms
78,540 KB
testcase_15 AC 1,322 ms
78,516 KB
testcase_16 AC 2,623 ms
78,524 KB
testcase_17 AC 2,019 ms
78,540 KB
testcase_18 AC 2,769 ms
78,524 KB
testcase_19 AC 600 ms
78,392 KB
testcase_20 AC 2,154 ms
78,540 KB
testcase_21 AC 3,352 ms
78,476 KB
testcase_22 AC 2,182 ms
78,540 KB
testcase_23 AC 1,413 ms
78,516 KB
testcase_24 AC 1,411 ms
78,516 KB
testcase_25 AC 1,400 ms
78,516 KB
testcase_26 AC 1,399 ms
78,516 KB
testcase_27 AC 2,342 ms
78,540 KB
testcase_28 AC 3,278 ms
78,476 KB
testcase_29 AC 2,812 ms
78,524 KB
testcase_30 AC 2,168 ms
78,540 KB
testcase_31 AC 2,172 ms
78,540 KB
testcase_32 AC 3,335 ms
78,476 KB
testcase_33 AC 1,408 ms
78,516 KB
testcase_34 AC 2,333 ms
78,540 KB
testcase_35 AC 2,170 ms
78,540 KB
testcase_36 AC 2,173 ms
78,540 KB
testcase_37 AC 1,404 ms
78,516 KB
testcase_38 AC 1,414 ms
78,516 KB
testcase_39 AC 3,285 ms
78,472 KB
testcase_40 AC 2,807 ms
78,524 KB
testcase_41 AC 2,328 ms
78,540 KB
testcase_42 AC 3,309 ms
78,476 KB
testcase_43 AC 601 ms
78,392 KB
testcase_44 AC 3,275 ms
78,476 KB
testcase_45 AC 1,399 ms
78,516 KB
testcase_46 AC 2,322 ms
78,540 KB
testcase_47 AC 1,394 ms
78,516 KB
testcase_48 AC 1,394 ms
78,516 KB
testcase_49 AC 601 ms
78,392 KB
testcase_50 AC 586 ms
78,392 KB
testcase_51 AC 2,665 ms
78,528 KB
testcase_52 AC 2,630 ms
78,528 KB
testcase_53 AC 3,071 ms
78,484 KB
testcase_54 AC 2,671 ms
78,528 KB
testcase_55 AC 3,085 ms
78,484 KB
testcase_56 AC 2,687 ms
78,524 KB
testcase_57 AC 2,695 ms
78,524 KB
testcase_58 AC 3,094 ms
78,488 KB
testcase_59 AC 3,173 ms
78,488 KB
testcase_60 AC 2,656 ms
78,528 KB
testcase_61 AC 3,121 ms
78,488 KB
testcase_62 AC 3,136 ms
78,488 KB
testcase_63 AC 3,184 ms
78,488 KB
testcase_64 AC 3,120 ms
78,488 KB
testcase_65 AC 3,114 ms
78,488 KB
testcase_66 AC 3,077 ms
78,488 KB
testcase_67 AC 3,105 ms
78,488 KB
testcase_68 AC 3,145 ms
78,488 KB
testcase_69 AC 3,150 ms
78,488 KB
testcase_70 AC 3,119 ms
78,488 KB
testcase_71 AC 3,158 ms
78,488 KB
testcase_72 AC 3,146 ms
78,488 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
      for p in range(k + 1):
        dp[l][r] |= ((dp[l][m] << p) & dp[m + 1][r])
        dp[l][r] |= ((dp[l][m] >> p) & dp[m + 1][r])
        dp[l][r] |= (dp[l][m] & (dp[m + 1][r] << p))
        dp[l][r] |= (dp[l][m] & (dp[m + 1][r] >> 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