結果

問題 No.1170 Never Want to Walk
ユーザー trineutrontrineutron
提出日時 2020-08-15 16:09:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 958 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 32,636 KB
最終ジャッジ日時 2024-04-19 01:21:17
合計ジャッジ時間 14,661 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 25 ms
10,624 KB
testcase_06 AC 29 ms
10,624 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 AC 34 ms
10,880 KB
testcase_13 AC 32 ms
10,880 KB
testcase_14 AC 32 ms
10,880 KB
testcase_15 AC 32 ms
10,880 KB
testcase_16 AC 32 ms
10,880 KB
testcase_17 AC 34 ms
10,752 KB
testcase_18 AC 34 ms
10,752 KB
testcase_19 AC 34 ms
10,880 KB
testcase_20 AC 30 ms
10,880 KB
testcase_21 AC 33 ms
10,752 KB
testcase_22 AC 35 ms
10,880 KB
testcase_23 AC 37 ms
10,752 KB
testcase_24 AC 37 ms
10,880 KB
testcase_25 AC 34 ms
10,752 KB
testcase_26 AC 35 ms
10,880 KB
testcase_27 AC 913 ms
31,736 KB
testcase_28 AC 920 ms
31,436 KB
testcase_29 AC 917 ms
32,320 KB
testcase_30 AC 934 ms
32,224 KB
testcase_31 AC 890 ms
31,628 KB
testcase_32 AC 898 ms
31,896 KB
testcase_33 AC 912 ms
31,432 KB
testcase_34 AC 958 ms
32,252 KB
testcase_35 AC 934 ms
32,540 KB
testcase_36 AC 904 ms
31,528 KB
testcase_37 AC 911 ms
31,924 KB
testcase_38 AC 951 ms
32,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

class UnionFind:
    par = []
    
    def __init__(self, n):
        self.par = [i for i in range(n)]
    
    def find(self, n):
        if self.par[n] == n:
            return n
        p = self.find(self.par[n])
        self.par[n] = p
        return p
    
    def merge(self, m, n):
        m = self.find(m)
        n = self.find(n)
        self.par[m] = n

sys.setrecursionlimit(100000)
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
v = [0] * (n + 1)
l = 0
r = 0
t = UnionFind(n)
for i in range(n):
    while l < n and x[l] < x[i] + a:
        l += 1
    while r < n and x[r] <= x[i] + b:
        r += 1
    if l == r:
        continue
    v[l] += 1
    v[r - 1] -= 1
    t.merge(i, l)
for i in range(n):
    v[i + 1] += v[i]
    if v[i] > 0:
        t.merge(i, i + 1)
y = [0] * n
s = [0] * n
for i in range(n):
    y[i] = t.find(i)
    s[y[i]] += 1
for i in range(n):
    print(s[y[i]])

0