結果

問題 No.2423 Merge Stones
ユーザー とりゐとりゐ
提出日時 2023-08-12 14:41:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,502 ms / 4,000 ms
コード長 712 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 77,404 KB
最終ジャッジ日時 2024-04-30 07:03:14
合計ジャッジ時間 153,648 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,948 KB
testcase_01 AC 67 ms
64,864 KB
testcase_02 AC 53 ms
63,528 KB
testcase_03 AC 52 ms
63,140 KB
testcase_04 AC 39 ms
53,940 KB
testcase_05 AC 65 ms
62,808 KB
testcase_06 AC 52 ms
65,020 KB
testcase_07 AC 53 ms
63,900 KB
testcase_08 AC 43 ms
55,824 KB
testcase_09 AC 41 ms
52,748 KB
testcase_10 AC 54 ms
65,680 KB
testcase_11 AC 3,172 ms
77,204 KB
testcase_12 AC 565 ms
76,704 KB
testcase_13 AC 3,009 ms
76,768 KB
testcase_14 AC 1,635 ms
77,000 KB
testcase_15 AC 1,484 ms
77,072 KB
testcase_16 AC 3,244 ms
77,132 KB
testcase_17 AC 1,637 ms
76,592 KB
testcase_18 AC 3,257 ms
76,840 KB
testcase_19 AC 567 ms
76,996 KB
testcase_20 AC 1,644 ms
76,744 KB
testcase_21 AC 2,994 ms
77,092 KB
testcase_22 AC 1,643 ms
76,716 KB
testcase_23 AC 1,486 ms
76,936 KB
testcase_24 AC 1,499 ms
76,876 KB
testcase_25 AC 1,505 ms
76,596 KB
testcase_26 AC 1,502 ms
76,592 KB
testcase_27 AC 2,690 ms
76,532 KB
testcase_28 AC 2,997 ms
76,944 KB
testcase_29 AC 3,257 ms
77,012 KB
testcase_30 AC 1,643 ms
76,860 KB
testcase_31 AC 1,645 ms
76,864 KB
testcase_32 AC 3,001 ms
76,712 KB
testcase_33 AC 1,505 ms
76,652 KB
testcase_34 AC 2,684 ms
76,720 KB
testcase_35 AC 1,643 ms
76,676 KB
testcase_36 AC 1,674 ms
76,656 KB
testcase_37 AC 1,506 ms
76,748 KB
testcase_38 AC 1,486 ms
76,948 KB
testcase_39 AC 3,006 ms
76,940 KB
testcase_40 AC 3,274 ms
76,728 KB
testcase_41 AC 2,703 ms
77,028 KB
testcase_42 AC 2,984 ms
76,752 KB
testcase_43 AC 563 ms
76,832 KB
testcase_44 AC 3,001 ms
76,772 KB
testcase_45 AC 1,491 ms
76,772 KB
testcase_46 AC 2,687 ms
76,580 KB
testcase_47 AC 1,496 ms
76,828 KB
testcase_48 AC 1,491 ms
77,128 KB
testcase_49 AC 560 ms
76,788 KB
testcase_50 AC 565 ms
76,928 KB
testcase_51 AC 3,502 ms
77,316 KB
testcase_52 AC 3,421 ms
77,000 KB
testcase_53 AC 3,208 ms
77,120 KB
testcase_54 AC 3,416 ms
77,128 KB
testcase_55 AC 3,153 ms
77,152 KB
testcase_56 AC 3,257 ms
76,608 KB
testcase_57 AC 3,293 ms
76,956 KB
testcase_58 AC 3,006 ms
77,404 KB
testcase_59 AC 3,000 ms
76,856 KB
testcase_60 AC 3,257 ms
76,856 KB
testcase_61 AC 3,183 ms
76,928 KB
testcase_62 AC 3,169 ms
77,080 KB
testcase_63 AC 3,167 ms
77,108 KB
testcase_64 AC 3,166 ms
77,212 KB
testcase_65 AC 3,172 ms
76,868 KB
testcase_66 AC 3,173 ms
77,192 KB
testcase_67 AC 3,160 ms
77,024 KB
testcase_68 AC 3,168 ms
76,788 KB
testcase_69 AC 3,177 ms
77,268 KB
testcase_70 AC 3,154 ms
77,104 KB
testcase_71 AC 3,018 ms
76,856 KB
testcase_72 AC 3,038 ms
77,204 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 i in range(n)]
for d in range(n):
  for l in range(n):
    r=l+d
    if l==r:
      dp[l][r]=1<<c[l]
      continue
    for m in range(l,r):
      for j in range(k+1):
        dp[l][r%n]|=(dp[l][m%n]<<j)&dp[(m+1)%n][r%n]
        dp[l][r%n]|=(dp[l][m%n]>>j)&dp[(m+1)%n][r%n]
        dp[l][r%n]|=(dp[(m+1)%n][r%n]<<j)&dp[l][m%n]
        dp[l][r%n]|=(dp[(m+1)%n][r%n]>>j)&dp[l][m%n]

ans=0
for i in range(n):
  for j in range(n):
    if dp[i][j]:
      res=0
      l=i
      r=j
      if r<l:
        r+=n
      for ii in range(l,r+1):
        res+=a[ii%n]
      ans=max(ans,res)

print(ans)
0