結果

問題 No.2423 Merge Stones
ユーザー Seed57_cashSeed57_cash
提出日時 2023-07-10 19:41:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,018 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 78,416 KB
最終ジャッジ日時 2023-10-10 01:22:15
合計ジャッジ時間 8,081 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
75,780 KB
testcase_01 AC 118 ms
78,344 KB
testcase_02 AC 124 ms
78,416 KB
testcase_03 AC 106 ms
77,336 KB
testcase_04 AC 73 ms
71,148 KB
testcase_05 AC 103 ms
77,392 KB
testcase_06 AC 105 ms
77,596 KB
testcase_07 AC 100 ms
76,620 KB
testcase_08 AC 94 ms
76,332 KB
testcase_09 AC 84 ms
76,292 KB
testcase_10 AC 106 ms
77,456 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 #

# 区間DPで、区間ごとに最後に残すことができる石を考える


n, k = map(int, input().split())
a_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
sum_a = sum(a_list)

dp = [[[0] * 50 for _1 in range(2 * n)] for _2 in range(2 * n)]

# 初期化
for i in range(2 * n):
	c = c_list[i % n] - 1
	dp[i][i][c] = 1

# 区間DP
for d in range(1, n):
	for i in range(2 * n - d):
		for j in range(d):
			for c in range(50):
				if dp[i][i + d][c] == 0 and dp[i][i + j][c] == 1:
					if sum(dp[i + j + 1][i + d][max(c - k, 0) : min(c + k + 1, 50)]) > 0:
						dp[i][i + d][c] = 1
						# print(i, i + d, c)
			for c in range(50):
				if dp[i][i + d][c] == 0 and dp[i + j + 1][i + d][c] == 1:
					if sum(dp[i][i + j][max(c - k, 0) : min(c + k + 1, 50)]) > 0:
						dp[i][i + d][c] = 1
						# print(i, i + d, c)
		
res = 0
a_list_dup = a_list + a_list
for i in range(n):
	for d in range(n):
		if sum(dp[i][i + d]) > 0:
			res = max(res, sum(a_list_dup[i:i + d + 1]))

print(res)
0