結果

問題 No.2643 Many Range Sums Problems
ユーザー shobonvipshobonvip
提出日時 2024-02-13 14:58:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,940 ms / 8,000 ms
コード長 1,050 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 113,276 KB
最終ジャッジ日時 2024-02-13 15:31:52
合計ジャッジ時間 46,981 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 2,246 ms
91,024 KB
testcase_04 AC 1,704 ms
86,036 KB
testcase_05 AC 1,571 ms
85,140 KB
testcase_06 AC 2,940 ms
94,800 KB
testcase_07 AC 2,068 ms
113,276 KB
testcase_08 AC 2,298 ms
92,052 KB
testcase_09 AC 2,476 ms
91,876 KB
testcase_10 AC 1,892 ms
106,748 KB
testcase_11 AC 1,008 ms
86,152 KB
testcase_12 AC 1,715 ms
93,176 KB
testcase_13 AC 2,573 ms
91,284 KB
testcase_14 AC 2,628 ms
91,924 KB
testcase_15 AC 2,423 ms
91,664 KB
testcase_16 AC 2,111 ms
89,104 KB
testcase_17 AC 1,999 ms
88,376 KB
testcase_18 AC 1,045 ms
81,552 KB
testcase_19 AC 191 ms
76,860 KB
testcase_20 AC 511 ms
78,464 KB
testcase_21 AC 158 ms
76,180 KB
testcase_22 AC 449 ms
78,724 KB
testcase_23 AC 723 ms
81,480 KB
testcase_24 AC 1,304 ms
88,732 KB
testcase_25 AC 1,194 ms
86,784 KB
testcase_26 AC 196 ms
76,620 KB
testcase_27 AC 207 ms
76,908 KB
testcase_28 AC 37 ms
53,460 KB
testcase_29 AC 36 ms
53,460 KB
testcase_30 AC 1,494 ms
93,560 KB
testcase_31 AC 2,794 ms
94,100 KB
testcase_32 AC 1,701 ms
93,432 KB
testcase_33 AC 1,744 ms
93,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

for i in range(n):
	r[i], x[i] = map(int,input().split())
	ikeru[i].append(r[i])
	ikeru[r[i]].append(i)

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

	mada = [n]
	tansaku = [0] * (n + 1)
	tansaku[n] = 1
	
	while mada:
		i = mada.pop()
		for j in ikeru[i]:
			if tansaku[j]:
				continue
			tansaku[j] = 1
			tmp_rx[j] += tmp_rx[i] + tmp_x[j]
			tmp_rv[j] += tmp_rv[i] + tmp_v[j]
			mada.append(j)
	
	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