結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,332 KB
testcase_01 AC 35 ms
53,332 KB
testcase_02 AC 36 ms
53,332 KB
testcase_03 AC 499 ms
82,388 KB
testcase_04 AC 428 ms
80,948 KB
testcase_05 AC 420 ms
80,580 KB
testcase_06 AC 567 ms
83,944 KB
testcase_07 AC 564 ms
83,960 KB
testcase_08 AC 519 ms
83,476 KB
testcase_09 AC 557 ms
83,960 KB
testcase_10 AC 503 ms
82,536 KB
testcase_11 AC 357 ms
79,892 KB
testcase_12 AC 727 ms
84,368 KB
testcase_13 AC 764 ms
84,108 KB
testcase_14 AC 528 ms
82,804 KB
testcase_15 AC 540 ms
83,288 KB
testcase_16 AC 459 ms
81,660 KB
testcase_17 AC 496 ms
81,928 KB
testcase_18 AC 345 ms
78,084 KB
testcase_19 AC 122 ms
76,248 KB
testcase_20 AC 194 ms
76,768 KB
testcase_21 AC 104 ms
76,088 KB
testcase_22 AC 224 ms
77,144 KB
testcase_23 AC 327 ms
78,672 KB
testcase_24 AC 519 ms
81,616 KB
testcase_25 AC 492 ms
80,972 KB
testcase_26 AC 125 ms
76,240 KB
testcase_27 AC 129 ms
76,240 KB
testcase_28 AC 36 ms
53,332 KB
testcase_29 AC 35 ms
53,332 KB
testcase_30 AC 558 ms
83,968 KB
testcase_31 AC 547 ms
84,144 KB
testcase_32 AC 778 ms
84,116 KB
testcase_33 AC 759 ms
83,980 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())

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

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

	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]

	mode = 1
	m_lb = - 10 ** 18
	m_ub = 10 ** 18
	for i in range(n):
		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:
			assert tar_v == -1
			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")
0