結果

問題 No.2423 Merge Stones
ユーザー dyktr_06dyktr_06
提出日時 2023-07-15 18:00:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,319 ms / 4,000 ms
コード長 878 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 79,368 KB
最終ジャッジ日時 2024-09-17 04:03:36
合計ジャッジ時間 79,797 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,760 KB
testcase_01 AC 53 ms
65,160 KB
testcase_02 AC 49 ms
63,648 KB
testcase_03 AC 42 ms
62,212 KB
testcase_04 AC 33 ms
53,352 KB
testcase_05 AC 39 ms
60,308 KB
testcase_06 AC 45 ms
62,732 KB
testcase_07 AC 41 ms
61,548 KB
testcase_08 AC 40 ms
60,464 KB
testcase_09 AC 35 ms
53,268 KB
testcase_10 AC 45 ms
63,732 KB
testcase_11 AC 2,036 ms
79,008 KB
testcase_12 AC 346 ms
78,504 KB
testcase_13 AC 978 ms
78,688 KB
testcase_14 AC 894 ms
78,892 KB
testcase_15 AC 843 ms
78,880 KB
testcase_16 AC 1,294 ms
78,980 KB
testcase_17 AC 948 ms
79,140 KB
testcase_18 AC 1,317 ms
79,368 KB
testcase_19 AC 344 ms
78,780 KB
testcase_20 AC 919 ms
79,080 KB
testcase_21 AC 1,005 ms
78,956 KB
testcase_22 AC 955 ms
79,128 KB
testcase_23 AC 869 ms
79,136 KB
testcase_24 AC 881 ms
78,936 KB
testcase_25 AC 854 ms
78,972 KB
testcase_26 AC 844 ms
78,824 KB
testcase_27 AC 1,111 ms
78,988 KB
testcase_28 AC 1,479 ms
78,932 KB
testcase_29 AC 1,230 ms
78,988 KB
testcase_30 AC 923 ms
79,056 KB
testcase_31 AC 935 ms
78,892 KB
testcase_32 AC 985 ms
79,024 KB
testcase_33 AC 834 ms
78,992 KB
testcase_34 AC 1,236 ms
79,032 KB
testcase_35 AC 924 ms
79,048 KB
testcase_36 AC 920 ms
78,960 KB
testcase_37 AC 838 ms
78,968 KB
testcase_38 AC 852 ms
79,288 KB
testcase_39 AC 967 ms
79,032 KB
testcase_40 AC 1,403 ms
78,988 KB
testcase_41 AC 1,306 ms
79,052 KB
testcase_42 AC 976 ms
78,940 KB
testcase_43 AC 339 ms
78,688 KB
testcase_44 AC 963 ms
79,224 KB
testcase_45 AC 840 ms
79,156 KB
testcase_46 AC 1,116 ms
78,884 KB
testcase_47 AC 915 ms
78,932 KB
testcase_48 AC 843 ms
79,204 KB
testcase_49 AC 345 ms
78,632 KB
testcase_50 AC 356 ms
79,044 KB
testcase_51 AC 1,771 ms
79,036 KB
testcase_52 AC 2,215 ms
79,028 KB
testcase_53 AC 2,026 ms
79,168 KB
testcase_54 AC 1,870 ms
79,136 KB
testcase_55 AC 2,319 ms
78,884 KB
testcase_56 AC 1,326 ms
79,148 KB
testcase_57 AC 1,315 ms
79,032 KB
testcase_58 AC 1,477 ms
79,100 KB
testcase_59 AC 1,013 ms
78,920 KB
testcase_60 AC 1,248 ms
79,364 KB
testcase_61 AC 2,004 ms
79,056 KB
testcase_62 AC 1,948 ms
79,000 KB
testcase_63 AC 1,970 ms
79,044 KB
testcase_64 AC 1,974 ms
78,948 KB
testcase_65 AC 1,963 ms
78,692 KB
testcase_66 AC 1,954 ms
78,840 KB
testcase_67 AC 1,925 ms
78,976 KB
testcase_68 AC 1,920 ms
78,972 KB
testcase_69 AC 1,910 ms
78,892 KB
testcase_70 AC 1,882 ms
78,892 KB
testcase_71 AC 1,843 ms
78,864 KB
testcase_72 AC 1,807 ms
79,236 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