結果

問題 No.2643 Many Range Sums Problems
ユーザー shobonvipshobonvip
提出日時 2024-02-13 15:05:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 815 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 79,416 KB
最終ジャッジ日時 2024-02-13 15:32:11
合計ジャッジ時間 17,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 34 ms
53,332 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 279 ms
77,444 KB
testcase_12 AC 1,065 ms
78,972 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 334 ms
76,816 KB
testcase_19 AC 116 ms
76,216 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 34 ms
53,332 KB
testcase_29 AC 34 ms
53,332 KB
testcase_30 AC 458 ms
78,332 KB
testcase_31 WA -
testcase_32 AC 794 ms
78,980 KB
testcase_33 AC 795 ms
79,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int,input().split())
r = [0] * n
x = [0] * n
for i in range(n):
	r[i], x[i] = map(int,input().split())

tmp_x = x[::]
tmp_v = [0] * n

for st in range(n):
	tmp_rx = [0] * (n + 1)
	tmp_rv = [0] * (n + 1)

	tmp_x[st] = 0
	tmp_v[st] = 1

	mode = 1
	m_lb = - 10 ** 18
	m_ub = 10 ** 18
	for i in range(n-1,-1,-1):
		tmp_rx[i] = tmp_rx[r[i]] + tmp_x[i]
		tmp_rv[i] = tmp_rv[r[i]] + tmp_v[i]
		tar_x = tmp_rx[i] - tmp_rx[i+1]
		tar_v = tmp_rv[i] - tmp_rv[i+1]
		# 0 <= tar_x + tar_v * M <= K
		if tar_v == 0:
			if not 0 <= tar_x <= k:
				mode = 0
		elif tar_v == 1:
			m_lb = max(m_lb, - tar_x)
			m_ub = min(m_ub, k - tar_x)
		else:
			m_lb = max(m_lb, tar_x - k)
			m_ub = min(m_ub, tar_x)
	
	if not m_lb <= m_ub:
		mode = 0

	if mode:
		print("Yes")
	else:
		print("No")

	tmp_x[st] = x[i]
	tmp_v[st] = 0
0