結果

問題 No.2423 Merge Stones
ユーザー Seed57_cashSeed57_cash
提出日時 2023-07-10 12:23:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,987 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 82,576 KB
最終ジャッジ日時 2023-10-10 01:10:03
合計ジャッジ時間 14,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,236 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 70 ms
71,544 KB
testcase_05 AC 70 ms
71,124 KB
testcase_06 AC 69 ms
70,944 KB
testcase_07 AC 72 ms
71,164 KB
testcase_08 AC 70 ms
71,180 KB
testcase_09 AC 67 ms
71,184 KB
testcase_10 AC 71 ms
71,396 KB
testcase_11 RE -
testcase_12 AC 101 ms
77,292 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 93 ms
77,200 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 93 ms
77,372 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 94 ms
77,144 KB
testcase_50 AC 97 ms
77,412 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 141 ms
78,456 KB
testcase_54 WA -
testcase_55 AC 145 ms
78,508 KB
testcase_56 AC 108 ms
77,784 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 最後にとる石について考える
# その色がどこからきたのかを考えると、その石は動かなかった扱いができる
# 左右に広げていく
# 新しい石に出会ったときに、貪欲に獲得する。自分は合成可能なこれまでの石のうち、一番最近のものになる


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)

res = a_list.copy()

for i in range(n):
	# iが動かない石
	# 右向きに進める
	# 各時点でなれる色と一番最近出会った時点
	colors = [[n + 1] * 50 for _ in range(n)]
	colors[0][c_list[i] - 1] = 0
	for j in range(1, n):
		new_color = c_list[(i + j) % n] - 1
		# 全探索
		# 現時点でi+jと合成可能な色のうち、一番新しい時点で出会ったものを探す
		min_j = n + 1
		for c in range(max(new_color - k, 0), min(new_color + k, 50) + 1):
			min_j = min(colors[j - 1][c], min_j)
		
		# 無理な場合
		if min_j == n + 1:
			break
		
		# 見つかった場合
		# copy
		for c in range(50):
			colors[j][c] = colors[min_j][c]
		colors[j][new_color] = j
		res[i] += a_list[(i + j) % n]
		
	# 左向きに進める
	# 各時点でなれる色と一番最近出会った時点
	colors = [[n + 1] * 50 for _ in range(n)]
	colors[0][c_list[i] - 1] = 0
	for j in range(1, n):
		new_color = c_list[(i - j) % n] - 1
		# 全探索
		# 現時点でi+jと合成可能な色のうち、一番新しい時点で出会ったものを探す
		min_j = n + 1
		for c in range(max(new_color - k, 0), min(new_color + k, 50) + 1):
			min_j = min(colors[j - 1][c], min_j)
		
		# 無理な場合
		if min_j == n + 1:
			break
		
		# 見つかった場合
		# copy
		for c in range(50):
			colors[j][c] = colors[min_j][c]
		colors[j][new_color] = j
		res[i] += a_list[(i - j) % n]
	
	# 1周していたら過剰になるので、全部の合計にする
	res[i] = min(res[i], sum_a)

print(max(res))
0