結果

問題 No.2643 Many Range Sums Problems
ユーザー shobonvipshobonvip
提出日時 2024-02-13 15:05:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 825 ms / 8,000 ms
コード長 816 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 79,236 KB
最終ジャッジ日時 2024-02-13 15:32:27
合計ジャッジ時間 13,864 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,332 KB
testcase_01 AC 35 ms
53,332 KB
testcase_02 AC 36 ms
53,332 KB
testcase_03 AC 434 ms
78,080 KB
testcase_04 AC 367 ms
77,700 KB
testcase_05 AC 353 ms
77,700 KB
testcase_06 AC 467 ms
78,972 KB
testcase_07 AC 462 ms
78,328 KB
testcase_08 AC 450 ms
78,628 KB
testcase_09 AC 539 ms
78,980 KB
testcase_10 AC 435 ms
78,340 KB
testcase_11 AC 297 ms
77,444 KB
testcase_12 AC 821 ms
79,228 KB
testcase_13 AC 729 ms
78,724 KB
testcase_14 AC 446 ms
78,464 KB
testcase_15 AC 458 ms
78,972 KB
testcase_16 AC 404 ms
78,212 KB
testcase_17 AC 433 ms
78,496 KB
testcase_18 AC 349 ms
76,816 KB
testcase_19 AC 120 ms
76,216 KB
testcase_20 AC 171 ms
76,328 KB
testcase_21 AC 96 ms
75,972 KB
testcase_22 AC 213 ms
76,312 KB
testcase_23 AC 321 ms
76,960 KB
testcase_24 AC 506 ms
77,824 KB
testcase_25 AC 476 ms
77,956 KB
testcase_26 AC 121 ms
76,336 KB
testcase_27 AC 127 ms
76,336 KB
testcase_28 AC 36 ms
53,332 KB
testcase_29 AC 35 ms
53,332 KB
testcase_30 AC 459 ms
78,332 KB
testcase_31 AC 488 ms
78,916 KB
testcase_32 AC 825 ms
78,980 KB
testcase_33 AC 825 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[st]
	tmp_v[st] = 0
0