結果

問題 No.2423 Merge Stones
ユーザー miya145592miya145592
提出日時 2023-08-13 01:57:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,809 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 60,928 KB
最終ジャッジ日時 2024-04-30 20:30:25
合計ジャッジ時間 6,558 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,216 KB
testcase_01 AC 52 ms
60,928 KB
testcase_02 AC 42 ms
54,388 KB
testcase_03 AC 42 ms
52,824 KB
testcase_04 AC 41 ms
52,616 KB
testcase_05 AC 41 ms
52,896 KB
testcase_06 AC 47 ms
53,532 KB
testcase_07 AC 41 ms
53,104 KB
testcase_08 AC 41 ms
53,120 KB
testcase_09 AC 41 ms
53,360 KB
testcase_10 AC 42 ms
53,200 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
A = tuple(map(int, input().split()))
C = tuple(map(int, input().split()))
dp = [[dict() for _ in range(N)] for _ in range(N)]
ans = 0
for i in range(N):
    dp[i][i][C[i]] = A[i]
    ans = max(ans, dp[i][i][C[i]])

for k in range(N-1):
    for i in range(N):
        for c in dp[i][(i+k)%N]:
            for j in range(min(k+1, N-k-1)):
                for nc in dp[(i+k+1)%N][(i+k+1+j)%N]:
                    if abs(c-nc)<=K:
                        if c not in dp[i][(i+k+1+j)%N]:
                            dp[i][(i+k+1+j)%N][c] = 0
                        dp[i][(i+k+1+j)%N][c] = max(dp[i][(i+k+1+j)%N][c], dp[i][(i+k)%N][c] + dp[(i+k+1)%N][(i+k+1+j)%N][nc])
                        ans = max(ans, dp[i][(i+k+1+j)%N][c])
                        if nc not in dp[i][(i+k+1+j)%N]:
                            dp[i][(i+k+1+j)%N][nc] = 0
                        dp[i][(i+k+1+j)%N][nc] = max(dp[i][(i+k+1+j)%N][nc], dp[i][(i+k)%N][c] + dp[(i+k+1)%N][(i+k+1+j)%N][nc])
                        ans = max(ans, dp[i][(i+k+1+j)%N][nc])
                for nc in dp[(i-1-j)%N][(i-1)%N]:
                    if abs(c-nc)<=K:
                        if c not in dp[(i-1-j)%N][(i+k)%N]:
                            dp[(i-1-j)%N][(i+k)%N][c] = 0
                        dp[(i-1-j)%N][(i+k)%N][c] = max(dp[(i-1-j)%N][(i+k)%N][c], dp[i][(i+k)%N][c] + dp[(i-1-j)%N][(i-1)%N][nc])
                        ans = max(ans, dp[(i-1-j)%N][(i+k)%N][c])
                        if nc not in dp[(i-1-j)%N][(i+k)%N]:
                            dp[(i-1-j)%N][(i+k)%N][nc] = 0
                        dp[(i-1-j)%N][(i+k)%N][nc] = max(dp[(i-1-j)%N][(i+k)%N][nc], dp[i][(i+k)%N][c] + dp[(i-1-j)%N][(i-1)%N][nc])
                        ans = max(ans, dp[(i-1-j)%N][(i+k)%N][nc])

#print(dp)
print(ans)
0