結果

問題 No.2423 Merge Stones
ユーザー とりゐとりゐ
提出日時 2023-08-12 15:06:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,032 ms / 4,000 ms
コード長 728 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 77,400 KB
最終ジャッジ日時 2024-04-30 08:10:07
合計ジャッジ時間 121,863 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,824 KB
testcase_01 AC 53 ms
64,840 KB
testcase_02 AC 53 ms
64,412 KB
testcase_03 AC 50 ms
63,644 KB
testcase_04 AC 40 ms
53,732 KB
testcase_05 AC 43 ms
61,160 KB
testcase_06 AC 51 ms
64,936 KB
testcase_07 AC 48 ms
63,120 KB
testcase_08 AC 39 ms
53,628 KB
testcase_09 AC 38 ms
53,960 KB
testcase_10 AC 50 ms
62,908 KB
testcase_11 AC 3,010 ms
76,868 KB
testcase_12 AC 247 ms
71,608 KB
testcase_13 AC 2,839 ms
76,752 KB
testcase_14 AC 1,379 ms
77,008 KB
testcase_15 AC 602 ms
77,300 KB
testcase_16 AC 2,355 ms
77,136 KB
testcase_17 AC 1,376 ms
76,768 KB
testcase_18 AC 2,344 ms
76,932 KB
testcase_19 AC 246 ms
71,908 KB
testcase_20 AC 1,371 ms
76,852 KB
testcase_21 AC 2,823 ms
76,712 KB
testcase_22 AC 1,390 ms
77,060 KB
testcase_23 AC 608 ms
77,116 KB
testcase_24 AC 612 ms
76,992 KB
testcase_25 AC 612 ms
76,940 KB
testcase_26 AC 612 ms
77,008 KB
testcase_27 AC 1,572 ms
76,932 KB
testcase_28 AC 2,834 ms
76,712 KB
testcase_29 AC 2,357 ms
76,748 KB
testcase_30 AC 1,413 ms
76,704 KB
testcase_31 AC 1,375 ms
77,136 KB
testcase_32 AC 2,831 ms
77,012 KB
testcase_33 AC 614 ms
77,148 KB
testcase_34 AC 1,575 ms
76,592 KB
testcase_35 AC 1,405 ms
76,724 KB
testcase_36 AC 1,372 ms
76,948 KB
testcase_37 AC 608 ms
76,912 KB
testcase_38 AC 604 ms
77,268 KB
testcase_39 AC 2,815 ms
76,712 KB
testcase_40 AC 2,354 ms
76,660 KB
testcase_41 AC 1,570 ms
76,848 KB
testcase_42 AC 2,818 ms
76,720 KB
testcase_43 AC 240 ms
71,748 KB
testcase_44 AC 2,816 ms
76,616 KB
testcase_45 AC 599 ms
77,144 KB
testcase_46 AC 1,566 ms
77,056 KB
testcase_47 AC 611 ms
77,108 KB
testcase_48 AC 605 ms
76,912 KB
testcase_49 AC 245 ms
71,304 KB
testcase_50 AC 246 ms
72,248 KB
testcase_51 AC 2,524 ms
77,204 KB
testcase_52 AC 2,505 ms
77,180 KB
testcase_53 AC 2,982 ms
77,012 KB
testcase_54 AC 2,556 ms
76,900 KB
testcase_55 AC 2,979 ms
76,724 KB
testcase_56 AC 2,362 ms
77,208 KB
testcase_57 AC 2,354 ms
76,980 KB
testcase_58 AC 2,914 ms
77,020 KB
testcase_59 AC 2,827 ms
76,920 KB
testcase_60 AC 2,355 ms
77,220 KB
testcase_61 AC 3,006 ms
76,788 KB
testcase_62 AC 3,032 ms
77,080 KB
testcase_63 AC 3,004 ms
77,064 KB
testcase_64 AC 2,979 ms
77,084 KB
testcase_65 AC 2,980 ms
77,016 KB
testcase_66 AC 2,985 ms
76,988 KB
testcase_67 AC 3,000 ms
77,088 KB
testcase_68 AC 3,011 ms
76,944 KB
testcase_69 AC 3,006 ms
76,992 KB
testcase_70 AC 2,979 ms
77,400 KB
testcase_71 AC 2,852 ms
77,208 KB
testcase_72 AC 2,859 ms
77,068 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
      dp[l][R]|=dp[l][M0]&dp[M1][R]
      for j in range(1,k+1):
        dp[l][R]|=(dp[l][M0]<<j)&dp[M1][R]
        dp[l][R]|=(dp[M1][R]<<j)&dp[l][M0]
        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