結果

問題 No.2643 Many Range Sums Problems
ユーザー KoiKoi
提出日時 2024-02-11 19:43:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,304 ms / 8,000 ms
コード長 1,342 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 93,252 KB
最終ジャッジ日時 2024-02-13 15:31:04
合計ジャッジ時間 75,359 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,600 KB
testcase_01 AC 42 ms
55,600 KB
testcase_02 AC 41 ms
55,600 KB
testcase_03 AC 3,482 ms
88,160 KB
testcase_04 AC 3,450 ms
86,900 KB
testcase_05 AC 2,990 ms
85,028 KB
testcase_06 AC 4,793 ms
90,704 KB
testcase_07 AC 2,080 ms
93,252 KB
testcase_08 AC 4,542 ms
90,264 KB
testcase_09 AC 4,326 ms
89,756 KB
testcase_10 AC 1,929 ms
91,228 KB
testcase_11 AC 1,433 ms
83,852 KB
testcase_12 AC 2,258 ms
88,576 KB
testcase_13 AC 5,304 ms
91,840 KB
testcase_14 AC 4,447 ms
88,656 KB
testcase_15 AC 4,488 ms
89,240 KB
testcase_16 AC 3,302 ms
87,648 KB
testcase_17 AC 3,672 ms
87,740 KB
testcase_18 AC 1,922 ms
81,624 KB
testcase_19 AC 281 ms
78,300 KB
testcase_20 AC 792 ms
79,480 KB
testcase_21 AC 213 ms
77,340 KB
testcase_22 AC 635 ms
79,496 KB
testcase_23 AC 1,040 ms
81,372 KB
testcase_24 AC 2,539 ms
87,268 KB
testcase_25 AC 1,786 ms
85,336 KB
testcase_26 AC 274 ms
78,440 KB
testcase_27 AC 303 ms
78,188 KB
testcase_28 AC 39 ms
55,600 KB
testcase_29 AC 42 ms
55,600 KB
testcase_30 AC 2,064 ms
88,460 KB
testcase_31 AC 4,821 ms
92,080 KB
testcase_32 AC 2,234 ms
88,696 KB
testcase_33 AC 2,260 ms
88,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,K=map(int,input().split())
R=[]
G=[[] for _ in range(N+1)]
for i in range(N):
    r,x=map(int,input().split())
    R.append(r)
    G[i].append([r,x])
    G[r].append([i,-x])
answers=[]
que=deque([0])
for i in range(N):
    Group_num=[-1]*(N+1)
    que=deque([0])
    Group_num[0]=1
    B=[0]*(N+1)
    seen=[False]*(N+1)
    seen[0]=True
    que=deque([0])
    diff_L=-10**19
    diff_R=10**19
    ans="Yes"
    while len(que):
        p=que.popleft()
        for (q,x) in G[p]:
            if(not seen[q]):
                if((p==i and q==R[i]) or (q==i and p==R[i])):
                    Group_num[q]=2
                else:
                    Group_num[q]=Group_num[p]
                que.append(q)
                seen[q]=True
                B[q]=B[p]+x
    for i in range(N):
        if(Group_num[i]==Group_num[i+1]):
            if(B[i+1]-B[i]<0 or B[i+1]-B[i]>K):
                ans="No"
        else:
            if(Group_num[i]==1 and Group_num[i+1]==2):
                Left=B[i+1]-B[i]-K
                Right=B[i+1]-B[i]
            else:
                Left=B[i]-B[i+1]
                Right=K+B[i]-B[i+1]
            diff_L=max(diff_L,Left)
            diff_R=min(diff_R,Right)
            if(diff_L>diff_R):
                ans="No"
    answers.append(ans)
for ans in answers:
    print(ans)
0