結果

問題 No.2643 Many Range Sums Problems
ユーザー chineristACchineristAC
提出日時 2024-02-19 22:38:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 948 ms / 8,000 ms
コード長 2,118 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 86,692 KB
最終ジャッジ日時 2024-02-19 22:38:29
合計ジャッジ時間 15,858 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
56,248 KB
testcase_01 AC 40 ms
56,248 KB
testcase_02 AC 41 ms
58,340 KB
testcase_03 AC 599 ms
82,756 KB
testcase_04 AC 474 ms
81,404 KB
testcase_05 AC 489 ms
81,480 KB
testcase_06 AC 690 ms
84,580 KB
testcase_07 AC 619 ms
85,076 KB
testcase_08 AC 481 ms
83,276 KB
testcase_09 AC 655 ms
85,140 KB
testcase_10 AC 576 ms
83,116 KB
testcase_11 AC 465 ms
81,464 KB
testcase_12 AC 948 ms
84,516 KB
testcase_13 AC 502 ms
86,692 KB
testcase_14 AC 463 ms
83,884 KB
testcase_15 AC 503 ms
84,132 KB
testcase_16 AC 505 ms
82,548 KB
testcase_17 AC 506 ms
83,080 KB
testcase_18 AC 239 ms
79,312 KB
testcase_19 AC 92 ms
77,264 KB
testcase_20 AC 186 ms
78,212 KB
testcase_21 AC 94 ms
77,216 KB
testcase_22 AC 260 ms
78,268 KB
testcase_23 AC 382 ms
79,292 KB
testcase_24 AC 628 ms
82,852 KB
testcase_25 AC 544 ms
81,700 KB
testcase_26 AC 130 ms
77,644 KB
testcase_27 AC 130 ms
77,644 KB
testcase_28 AC 41 ms
56,248 KB
testcase_29 AC 41 ms
56,248 KB
testcase_30 AC 691 ms
84,892 KB
testcase_31 AC 573 ms
84,304 KB
testcase_32 AC 927 ms
84,260 KB
testcase_33 AC 944 ms
84,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

class UnionFindVerSize():
    def __init__(self, N):
        self._parent = [n for n in range(0, N)]
        self._size = [1] * N
        self.group = N

    def find_root(self, x):
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x])
        return self._parent[x]

    def unite(self, x, y):
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        self.group -= 1

        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        return self._size[self.find_root(x)]

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)
    

N,K = mi()
cond = []
for _ in range(N):
    r,x = mi()
    cond.append((r,x))

res = []
for i in range(N):
    tmp = [(0,0)] * (N+1)
    for j in range(N)[::-1]:
        if j!=i:
            r,x = cond[j]
            """
            A_j + tmp[j+1] - tmp[r] = X[j]
            """
            a,b = -(tmp[j+1][0] - tmp[r][0]),x-(tmp[j+1][1] - tmp[r][1])
            tmp[j] = (tmp[j+1][0]+a,tmp[j+1][1]+b)
        else:
            tmp[j] = (tmp[j+1][0]+1,tmp[j+1][1])
    
    #print(tmp)
    
    l,r = 0,K
    for j in range(N):
        a,b = tmp[j][0]-tmp[j+1][0],tmp[j][1]-tmp[j+1][1]
        #print(a,b)
        if a == 0:
            if not 0 <= b <= K:
                res.append("No")
                break
        elif 0 < a:
            l = max(l,(-b+a-1)//a)
            r = min(r,(K-b)//a)
        else:
            r = min(r,(b)//(-a))
            l = max(l,(-K+b+(-a)-1)//(-a))
    else:
        #print("lr",l,r)
        res.append("Yes" if l <= r else "No")

print(*res,sep="\n")
        
    

        
        
0