結果
問題 | No.945 YKC饅頭 |
ユーザー |
![]() |
提出日時 | 2021-08-29 17:43:13 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 914 ms / 2,000 ms |
コード長 | 1,098 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 20,608 KB |
最終ジャッジ日時 | 2024-11-22 06:58:05 |
合計ジャッジ時間 | 25,990 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 74 |
ソースコード
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)