結果

問題 No.2423 Merge Stones
ユーザー とりゐとりゐ
提出日時 2023-08-12 15:04:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,764 ms / 4,000 ms
コード長 711 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 77,212 KB
最終ジャッジ日時 2024-04-30 08:04:32
合計ジャッジ時間 124,036 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,480 KB
testcase_01 AC 54 ms
64,936 KB
testcase_02 AC 48 ms
63,428 KB
testcase_03 AC 48 ms
62,812 KB
testcase_04 AC 37 ms
53,096 KB
testcase_05 AC 47 ms
61,056 KB
testcase_06 AC 51 ms
62,996 KB
testcase_07 AC 47 ms
62,256 KB
testcase_08 AC 39 ms
53,668 KB
testcase_09 AC 38 ms
53,440 KB
testcase_10 AC 50 ms
63,016 KB
testcase_11 AC 2,638 ms
77,120 KB
testcase_12 AC 344 ms
76,992 KB
testcase_13 AC 2,487 ms
76,968 KB
testcase_14 AC 1,398 ms
76,996 KB
testcase_15 AC 1,121 ms
76,888 KB
testcase_16 AC 2,554 ms
76,836 KB
testcase_17 AC 1,355 ms
76,824 KB
testcase_18 AC 2,570 ms
77,000 KB
testcase_19 AC 342 ms
76,920 KB
testcase_20 AC 1,351 ms
76,844 KB
testcase_21 AC 2,450 ms
77,000 KB
testcase_22 AC 1,360 ms
77,116 KB
testcase_23 AC 1,124 ms
76,980 KB
testcase_24 AC 1,121 ms
76,856 KB
testcase_25 AC 1,120 ms
76,776 KB
testcase_26 AC 1,118 ms
76,768 KB
testcase_27 AC 2,094 ms
76,828 KB
testcase_28 AC 2,480 ms
77,164 KB
testcase_29 AC 2,544 ms
76,920 KB
testcase_30 AC 1,350 ms
76,740 KB
testcase_31 AC 1,371 ms
76,844 KB
testcase_32 AC 2,458 ms
76,968 KB
testcase_33 AC 1,131 ms
76,980 KB
testcase_34 AC 2,112 ms
76,904 KB
testcase_35 AC 1,366 ms
76,716 KB
testcase_36 AC 1,362 ms
77,016 KB
testcase_37 AC 1,140 ms
76,732 KB
testcase_38 AC 1,115 ms
76,824 KB
testcase_39 AC 2,460 ms
76,904 KB
testcase_40 AC 2,547 ms
76,736 KB
testcase_41 AC 2,083 ms
76,572 KB
testcase_42 AC 2,467 ms
76,596 KB
testcase_43 AC 350 ms
76,844 KB
testcase_44 AC 2,498 ms
77,164 KB
testcase_45 AC 1,132 ms
76,732 KB
testcase_46 AC 2,091 ms
76,784 KB
testcase_47 AC 1,124 ms
76,972 KB
testcase_48 AC 1,127 ms
76,784 KB
testcase_49 AC 347 ms
77,196 KB
testcase_50 AC 346 ms
76,700 KB
testcase_51 AC 2,718 ms
76,972 KB
testcase_52 AC 2,764 ms
76,972 KB
testcase_53 AC 2,628 ms
77,052 KB
testcase_54 AC 2,726 ms
77,044 KB
testcase_55 AC 2,622 ms
76,980 KB
testcase_56 AC 2,556 ms
77,080 KB
testcase_57 AC 2,555 ms
76,680 KB
testcase_58 AC 2,482 ms
77,108 KB
testcase_59 AC 2,452 ms
76,932 KB
testcase_60 AC 2,559 ms
76,720 KB
testcase_61 AC 2,619 ms
77,108 KB
testcase_62 AC 2,619 ms
77,212 KB
testcase_63 AC 2,614 ms
77,032 KB
testcase_64 AC 2,630 ms
76,760 KB
testcase_65 AC 2,659 ms
77,180 KB
testcase_66 AC 2,670 ms
77,180 KB
testcase_67 AC 2,631 ms
77,060 KB
testcase_68 AC 2,652 ms
76,904 KB
testcase_69 AC 2,644 ms
76,904 KB
testcase_70 AC 2,634 ms
77,188 KB
testcase_71 AC 2,505 ms
77,168 KB
testcase_72 AC 2,489 ms
77,108 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
    R=r%n
    if l==r:
      dp[l][r]=1<<c[l]
      continue
    for m in range(l,r):
      M0=m%n
      M1=(m+1)%n
      for j in range(k+1):
        dp[l][R]|=(dp[l][M0]<<j)&dp[M1][R]
        dp[l][R]|=(dp[M1][R]<<j)&dp[l][M0]
        if j!=0:
          dp[l][R]|=(dp[l][M0]>>j)&dp[M1][R]
          dp[l][R]|=(dp[M1][R]>>j)&dp[l][M0]

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

print(ans)
0