結果
問題 | No.674 n連勤 |
ユーザー | maspy |
提出日時 | 2020-03-21 14:53:55 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 269 ms / 2,000 ms |
コード長 | 1,723 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 10,904 KB |
実行使用メモリ | 25,324 KB |
最終ジャッジ日時 | 2023-08-24 13:32:59 |
合計ジャッジ時間 | 4,284 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,212 KB |
testcase_01 | AC | 16 ms
8,140 KB |
testcase_02 | AC | 16 ms
8,068 KB |
testcase_03 | AC | 16 ms
8,092 KB |
testcase_04 | AC | 16 ms
8,164 KB |
testcase_05 | AC | 16 ms
8,068 KB |
testcase_06 | AC | 16 ms
8,064 KB |
testcase_07 | AC | 15 ms
8,104 KB |
testcase_08 | AC | 16 ms
8,140 KB |
testcase_09 | AC | 15 ms
8,024 KB |
testcase_10 | AC | 16 ms
8,240 KB |
testcase_11 | AC | 34 ms
10,020 KB |
testcase_12 | AC | 31 ms
9,608 KB |
testcase_13 | AC | 101 ms
14,376 KB |
testcase_14 | AC | 211 ms
25,324 KB |
testcase_15 | AC | 215 ms
23,308 KB |
testcase_16 | AC | 268 ms
25,024 KB |
testcase_17 | AC | 269 ms
25,240 KB |
testcase_18 | AC | 212 ms
23,076 KB |
testcase_19 | AC | 236 ms
25,196 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class UnionFind: def __init__(self, N): self.root = list(range(N)) self.size = [1] * (N) self.left_end = list(range(N)) self.right_end = list(range(N)) def find_root(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return False sx, sy = self.size[x], self.size[y] if sx < sy: self.root[x] = y self.size[y] += sx self.left_end[y] = min(self.left_end[x], self.left_end[y]) self.right_end[y] = max(self.right_end[x], self.right_end[y]) else: self.root[y] = x self.size[x] += sy self.left_end[x] = min(self.left_end[x], self.left_end[y]) self.right_end[x] = max(self.right_end[x], self.right_end[y]) return True D, Q = map(int, readline().split()) m = map(int, read().split()) A, B = zip(*zip(m, m)) B = tuple(b + 1 for b in B) X = sorted(set(A + B)) x_to_i = {v: i for i, v in enumerate(sorted(set(A + B)))} uf = UnionFind(len(X)) find = uf.find_root merge = uf.merge answer = 0 for a, b in zip(A, B): a = x_to_i[a] b = x_to_i[b] a = uf.right_end[find(a)] b = uf.left_end[find(b)] while a < b: merge(a, a + 1) a = uf.right_end[find(a)] b = find(b) width = X[uf.right_end[b]] - X[uf.left_end[b]] if answer < width: answer = width print(answer)