結果

問題 No.945 YKC饅頭
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-29 17:43:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 937 ms / 2,000 ms
コード長 1,098 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 20,736 KB
最終ジャッジ日時 2024-05-01 23:10:51
合計ジャッジ時間 24,922 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 31 ms
11,008 KB
testcase_08 AC 29 ms
10,752 KB
testcase_09 AC 28 ms
10,880 KB
testcase_10 AC 28 ms
10,752 KB
testcase_11 AC 27 ms
10,752 KB
testcase_12 AC 29 ms
11,008 KB
testcase_13 AC 30 ms
11,008 KB
testcase_14 AC 30 ms
10,752 KB
testcase_15 AC 29 ms
10,880 KB
testcase_16 AC 27 ms
10,752 KB
testcase_17 AC 30 ms
10,880 KB
testcase_18 AC 29 ms
10,880 KB
testcase_19 AC 27 ms
10,880 KB
testcase_20 AC 27 ms
10,880 KB
testcase_21 AC 28 ms
11,008 KB
testcase_22 AC 30 ms
10,880 KB
testcase_23 AC 32 ms
10,752 KB
testcase_24 AC 31 ms
10,880 KB
testcase_25 AC 33 ms
10,880 KB
testcase_26 AC 33 ms
10,880 KB
testcase_27 AC 30 ms
10,752 KB
testcase_28 AC 29 ms
10,752 KB
testcase_29 AC 29 ms
10,752 KB
testcase_30 AC 28 ms
10,752 KB
testcase_31 AC 97 ms
12,672 KB
testcase_32 AC 189 ms
16,128 KB
testcase_33 AC 317 ms
16,896 KB
testcase_34 AC 471 ms
16,128 KB
testcase_35 AC 758 ms
19,456 KB
testcase_36 AC 480 ms
11,392 KB
testcase_37 AC 442 ms
11,776 KB
testcase_38 AC 457 ms
12,672 KB
testcase_39 AC 257 ms
15,232 KB
testcase_40 AC 271 ms
18,328 KB
testcase_41 AC 177 ms
14,732 KB
testcase_42 AC 589 ms
14,848 KB
testcase_43 AC 429 ms
11,136 KB
testcase_44 AC 615 ms
17,408 KB
testcase_45 AC 653 ms
13,568 KB
testcase_46 AC 126 ms
14,592 KB
testcase_47 AC 467 ms
14,976 KB
testcase_48 AC 115 ms
11,392 KB
testcase_49 AC 281 ms
15,744 KB
testcase_50 AC 656 ms
13,824 KB
testcase_51 AC 879 ms
19,072 KB
testcase_52 AC 937 ms
19,648 KB
testcase_53 AC 872 ms
18,036 KB
testcase_54 AC 854 ms
19,328 KB
testcase_55 AC 867 ms
20,120 KB
testcase_56 AC 249 ms
20,736 KB
testcase_57 AC 85 ms
16,768 KB
testcase_58 AC 677 ms
17,664 KB
testcase_59 AC 787 ms
17,664 KB
testcase_60 AC 393 ms
17,536 KB
testcase_61 AC 697 ms
17,408 KB
testcase_62 AC 695 ms
17,536 KB
testcase_63 AC 52 ms
15,744 KB
testcase_64 AC 442 ms
17,664 KB
testcase_65 AC 358 ms
17,536 KB
testcase_66 AC 361 ms
17,536 KB
testcase_67 AC 570 ms
17,664 KB
testcase_68 AC 415 ms
17,536 KB
testcase_69 AC 176 ms
17,280 KB
testcase_70 AC 222 ms
17,536 KB
testcase_71 AC 224 ms
17,408 KB
testcase_72 AC 502 ms
17,408 KB
testcase_73 AC 740 ms
17,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * n
        self.rank = [0] * n

    def find(self, x):
        stack = []
        while self.root[x] > 0:
            stack.append(x)
            x = self.root[x]
        for i in stack:
            self.root[i] = x
        return x

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.root[y] += self.root[x]
        self.root[x] = y
        return True

    def size(self, x):
        return -self.root[self.find(x)]


N, M = map(int, input().split())

yck = [0] * N
uf = UF_tree(N+1)
ans = [0, 0, 0]

for _ in range(M):
    l, r, t = input().rstrip().split()
    L = int(l) - 1
    R = int(r)
    i = "YKC".find(t)

    while L < R:
        if not yck[L]:
            ans[i] += 1
        yck[L] = 1
        uf.unite(L, L+1)
        L = uf.find(L)

print(*ans)
0