結果
問題 | No.1266 7 Colors |
ユーザー | terasa |
提出日時 | 2022-06-11 16:02:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 942 ms / 3,000 ms |
コード長 | 2,557 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 116,580 KB |
最終ジャッジ日時 | 2024-09-22 03:14:45 |
合計ジャッジ時間 | 16,888 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,904 KB |
testcase_01 | AC | 40 ms
55,408 KB |
testcase_02 | AC | 41 ms
55,704 KB |
testcase_03 | AC | 733 ms
90,032 KB |
testcase_04 | AC | 777 ms
101,212 KB |
testcase_05 | AC | 741 ms
91,416 KB |
testcase_06 | AC | 776 ms
103,296 KB |
testcase_07 | AC | 823 ms
107,148 KB |
testcase_08 | AC | 792 ms
102,004 KB |
testcase_09 | AC | 785 ms
97,292 KB |
testcase_10 | AC | 770 ms
95,840 KB |
testcase_11 | AC | 739 ms
92,024 KB |
testcase_12 | AC | 728 ms
93,100 KB |
testcase_13 | AC | 752 ms
94,460 KB |
testcase_14 | AC | 753 ms
90,884 KB |
testcase_15 | AC | 826 ms
107,428 KB |
testcase_16 | AC | 814 ms
93,956 KB |
testcase_17 | AC | 791 ms
106,588 KB |
testcase_18 | AC | 942 ms
116,580 KB |
testcase_19 | AC | 881 ms
107,896 KB |
testcase_20 | AC | 895 ms
107,896 KB |
testcase_21 | AC | 264 ms
84,212 KB |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class UnionFind: def __init__(self, N): self.N = N self.par = [-1] * N def find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] 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.par[x] += self.par[y] self.par[y] = x return True def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return -self.par[self.find(x)] def roots(self): return [i for i in range(self.N) if self.par[i] < 0] def members(self, x): p = self.find(x) return [i for i in range(self.N) if self.find(i) == p] def h(i, j): return i * 7 + j N, M, Q = map(int, input().split()) S = [[int(c) for c in input()[:-1]] for _ in range(N)] uf = UnionFind(7 * N) A = list(range(7)) B = list(range(1, 7)) + [0] for i in range(N): s = S[i] for a, b in zip(A, B): if s[a] * s[b] > 0: uf.unite(h(i, a), h(i, b)) E = [[] for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 E[u].append(v) E[v].append(u) for j in range(7): if S[u][j] * S[v][j] > 0: uf.unite(h(u, j), h(v, j)) for _ in range(Q): t, x, y = map(int, input().split()) x -= 1 y -= 1 if t == 1: S[x][y] = 1 pre = (y - 1) % 7 nxt = (y + 1) % 7 for j in [pre, nxt]: if S[x][j] > 0: uf.unite(h(x, y), h(x, j)) for d in E[x]: if S[d][y]: uf.unite(h(x, y), h(d, y)) else: print(uf.size(h(x, 0)))