結果

問題 No.2423 Merge Stones
ユーザー dyktr_06dyktr_06
提出日時 2023-07-15 17:50:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 854 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 78,820 KB
最終ジャッジ日時 2023-10-17 04:10:40
合計ジャッジ時間 105,008 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,532 KB
testcase_01 AC 55 ms
66,376 KB
testcase_02 AC 50 ms
64,300 KB
testcase_03 AC 48 ms
61,952 KB
testcase_04 AC 38 ms
53,532 KB
testcase_05 AC 43 ms
59,848 KB
testcase_06 AC 48 ms
62,092 KB
testcase_07 AC 45 ms
61,872 KB
testcase_08 AC 42 ms
59,848 KB
testcase_09 AC 38 ms
53,532 KB
testcase_10 AC 50 ms
64,300 KB
testcase_11 AC 3,757 ms
78,556 KB
testcase_12 AC 169 ms
78,224 KB
testcase_13 AC 830 ms
78,556 KB
testcase_14 AC 759 ms
78,480 KB
testcase_15 AC 688 ms
78,544 KB
testcase_16 AC 1,206 ms
78,620 KB
testcase_17 AC 763 ms
78,516 KB
testcase_18 AC 1,212 ms
78,608 KB
testcase_19 AC 169 ms
78,224 KB
testcase_20 AC 758 ms
78,480 KB
testcase_21 AC 786 ms
78,556 KB
testcase_22 AC 761 ms
78,480 KB
testcase_23 AC 685 ms
78,544 KB
testcase_24 AC 686 ms
78,544 KB
testcase_25 AC 686 ms
78,544 KB
testcase_26 AC 690 ms
78,544 KB
testcase_27 AC 989 ms
78,608 KB
testcase_28 AC 1,336 ms
78,556 KB
testcase_29 AC 1,168 ms
78,620 KB
testcase_30 AC 763 ms
78,516 KB
testcase_31 AC 758 ms
78,516 KB
testcase_32 AC 787 ms
78,556 KB
testcase_33 AC 685 ms
78,544 KB
testcase_34 AC 1,119 ms
78,608 KB
testcase_35 AC 761 ms
78,480 KB
testcase_36 AC 758 ms
78,480 KB
testcase_37 AC 685 ms
78,544 KB
testcase_38 AC 687 ms
78,544 KB
testcase_39 AC 786 ms
78,556 KB
testcase_40 AC 1,224 ms
78,608 KB
testcase_41 AC 1,110 ms
78,608 KB
testcase_42 AC 794 ms
78,552 KB
testcase_43 AC 168 ms
78,224 KB
testcase_44 AC 786 ms
78,556 KB
testcase_45 AC 685 ms
78,544 KB
testcase_46 AC 981 ms
78,608 KB
testcase_47 AC 685 ms
78,544 KB
testcase_48 AC 683 ms
78,544 KB
testcase_49 AC 169 ms
78,224 KB
testcase_50 AC 169 ms
78,224 KB
testcase_51 AC 3,173 ms
78,608 KB
testcase_52 AC 3,715 ms
78,628 KB
testcase_53 AC 3,779 ms
78,556 KB
testcase_54 AC 3,170 ms
78,608 KB
testcase_55 TLE -
testcase_56 AC 1,223 ms
78,608 KB
testcase_57 AC 1,212 ms
78,620 KB
testcase_58 AC 1,362 ms
78,556 KB
testcase_59 AC 1,709 ms
78,556 KB
testcase_60 AC 1,758 ms
78,608 KB
testcase_61 AC 3,744 ms
78,556 KB
testcase_62 AC 3,780 ms
78,556 KB
testcase_63 AC 3,680 ms
78,556 KB
testcase_64 AC 3,768 ms
78,556 KB
testcase_65 AC 3,770 ms
78,556 KB
testcase_66 AC 3,701 ms
78,556 KB
testcase_67 AC 3,746 ms
78,556 KB
testcase_68 AC 3,781 ms
78,820 KB
testcase_69 AC 3,779 ms
78,528 KB
testcase_70 AC 3,467 ms
78,556 KB
testcase_71 AC 2,707 ms
78,556 KB
testcase_72 AC 2,709 ms
78,556 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):
        if dp[l][m] == 0 or dp[m + 1][r] == 0:
          continue
        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