結果

問題 No.2423 Merge Stones
ユーザー Seed57_cashSeed57_cash
提出日時 2023-07-16 17:41:41
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,018 bytes
コンパイル時間 3,968 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 76,816 KB
最終ジャッジ日時 2023-10-17 16:13:23
合計ジャッジ時間 11,933 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
61,752 KB
testcase_01 AC 111 ms
76,816 KB
testcase_02 AC 81 ms
76,552 KB
testcase_03 AC 69 ms
73,312 KB
testcase_04 AC 36 ms
53,484 KB
testcase_05 AC 63 ms
70,724 KB
testcase_06 AC 65 ms
70,724 KB
testcase_07 AC 58 ms
68,660 KB
testcase_08 AC 52 ms
66,220 KB
testcase_09 AC 47 ms
62,072 KB
testcase_10 AC 63 ms
70,724 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