結果

問題 No.2423 Merge Stones
ユーザー sepa38sepa38
提出日時 2023-07-15 17:00:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,796 ms / 4,000 ms
コード長 780 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 76,296 KB
最終ジャッジ日時 2023-10-17 05:24:29
合計ジャッジ時間 130,712 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,316 KB
testcase_01 AC 52 ms
64,024 KB
testcase_02 AC 51 ms
61,956 KB
testcase_03 AC 49 ms
61,968 KB
testcase_04 AC 42 ms
53,316 KB
testcase_05 AC 48 ms
61,932 KB
testcase_06 AC 52 ms
64,024 KB
testcase_07 AC 51 ms
61,956 KB
testcase_08 AC 42 ms
55,364 KB
testcase_09 AC 40 ms
53,316 KB
testcase_10 AC 52 ms
64,032 KB
testcase_11 AC 2,778 ms
76,232 KB
testcase_12 AC 637 ms
76,108 KB
testcase_13 AC 2,773 ms
76,076 KB
testcase_14 AC 1,504 ms
75,976 KB
testcase_15 AC 1,305 ms
76,044 KB
testcase_16 AC 2,338 ms
76,136 KB
testcase_17 AC 1,517 ms
75,976 KB
testcase_18 AC 2,332 ms
76,136 KB
testcase_19 AC 639 ms
76,108 KB
testcase_20 AC 1,515 ms
75,976 KB
testcase_21 AC 2,779 ms
76,076 KB
testcase_22 AC 1,514 ms
75,976 KB
testcase_23 AC 1,313 ms
76,044 KB
testcase_24 AC 1,314 ms
76,044 KB
testcase_25 AC 1,311 ms
76,044 KB
testcase_26 AC 1,311 ms
76,044 KB
testcase_27 AC 1,913 ms
76,124 KB
testcase_28 AC 2,764 ms
76,076 KB
testcase_29 AC 2,345 ms
76,136 KB
testcase_30 AC 1,508 ms
75,976 KB
testcase_31 AC 1,510 ms
75,976 KB
testcase_32 AC 2,768 ms
76,076 KB
testcase_33 AC 1,311 ms
76,044 KB
testcase_34 AC 1,912 ms
76,124 KB
testcase_35 AC 1,506 ms
75,976 KB
testcase_36 AC 1,512 ms
75,976 KB
testcase_37 AC 1,303 ms
76,044 KB
testcase_38 AC 1,306 ms
76,044 KB
testcase_39 AC 2,769 ms
76,076 KB
testcase_40 AC 2,348 ms
76,136 KB
testcase_41 AC 1,921 ms
76,124 KB
testcase_42 AC 2,773 ms
76,076 KB
testcase_43 AC 639 ms
76,104 KB
testcase_44 AC 2,763 ms
76,080 KB
testcase_45 AC 1,310 ms
76,044 KB
testcase_46 AC 1,974 ms
76,124 KB
testcase_47 AC 1,312 ms
76,044 KB
testcase_48 AC 1,314 ms
76,044 KB
testcase_49 AC 635 ms
76,108 KB
testcase_50 AC 644 ms
76,100 KB
testcase_51 AC 2,347 ms
76,292 KB
testcase_52 AC 2,345 ms
76,296 KB
testcase_53 AC 2,779 ms
76,088 KB
testcase_54 AC 2,347 ms
76,296 KB
testcase_55 AC 2,770 ms
76,088 KB
testcase_56 AC 2,338 ms
76,132 KB
testcase_57 AC 2,338 ms
76,136 KB
testcase_58 AC 2,765 ms
76,088 KB
testcase_59 AC 2,763 ms
76,076 KB
testcase_60 AC 2,337 ms
76,136 KB
testcase_61 AC 2,775 ms
76,232 KB
testcase_62 AC 2,780 ms
76,088 KB
testcase_63 AC 2,766 ms
76,236 KB
testcase_64 AC 2,784 ms
76,088 KB
testcase_65 AC 2,772 ms
76,088 KB
testcase_66 AC 2,763 ms
76,236 KB
testcase_67 AC 2,770 ms
76,232 KB
testcase_68 AC 2,767 ms
76,088 KB
testcase_69 AC 2,781 ms
76,088 KB
testcase_70 AC 2,796 ms
76,236 KB
testcase_71 AC 2,769 ms
76,088 KB
testcase_72 AC 2,771 ms
76,088 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] * n for _ in range(n)]
for i in range(n):
  dp[i][i] = 1 << c[i]
for i in range(1, n):
  for l in range(n):
    r = (l + i) % n
    for j in range(i):
      m = (l + j) % n
      for p in range(k+1):
        dp[l][r] |= ((dp[l][m] << p) & dp[(m+1)%n][r])
        dp[l][r] |= ((dp[l][m] >> p) & dp[(m+1)%n][r])
        dp[l][r] |= (dp[l][m] & (dp[(m+1)%n][r] << p))
        dp[l][r] |= (dp[l][m] & (dp[(m+1)%n][r] >> p))
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
ans = 0
for i in range(n):
  for j in range(n):
    if dp[i][j]:
      if i <= j:
        ans = max(ans, s[j+1]-s[i])
      else:
        ans = max(ans, s[n]-s[i]+s[j+1])
print(ans)
0