結果
問題 | No.1266 7 Colors |
ユーザー | ayaoni |
提出日時 | 2020-10-23 23:36:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,432 ms / 3,000 ms |
コード長 | 2,652 bytes |
コンパイル時間 | 1,520 ms |
コンパイル使用メモリ | 86,904 KB |
実行使用メモリ | 131,652 KB |
最終ジャッジ日時 | 2023-09-28 18:52:18 |
合計ジャッジ時間 | 19,185 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
71,096 KB |
testcase_01 | AC | 80 ms
71,132 KB |
testcase_02 | AC | 79 ms
71,172 KB |
testcase_03 | AC | 667 ms
91,524 KB |
testcase_04 | AC | 1,187 ms
119,396 KB |
testcase_05 | AC | 661 ms
92,220 KB |
testcase_06 | AC | 1,278 ms
122,512 KB |
testcase_07 | AC | 1,361 ms
129,652 KB |
testcase_08 | AC | 1,163 ms
118,796 KB |
testcase_09 | AC | 983 ms
109,064 KB |
testcase_10 | AC | 1,000 ms
107,264 KB |
testcase_11 | AC | 831 ms
97,412 KB |
testcase_12 | AC | 887 ms
100,672 KB |
testcase_13 | AC | 917 ms
102,260 KB |
testcase_14 | AC | 636 ms
92,016 KB |
testcase_15 | AC | 1,432 ms
131,652 KB |
testcase_16 | AC | 896 ms
101,108 KB |
testcase_17 | AC | 1,380 ms
129,004 KB |
testcase_18 | AC | 411 ms
127,808 KB |
testcase_19 | AC | 374 ms
125,336 KB |
testcase_20 | AC | 373 ms
125,760 KB |
testcase_21 | AC | 207 ms
81,416 KB |
ソースコード
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) class UnionFind: def __init__(self,n): self.par = [i for i in range(n+1)] # 親のノード番号 self.rank = [0]*(n+1) self.X = [1]*(n+1) def find(self,x): # xの根のノード番号 if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self,x,y): # x,yが同じグループか否か return self.find(x) == self.find(y) def unite(self,x,y): # x,yの属するグループの併合 x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: x,y = y,x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.X[x] += self.X[y] N,M,Q = MI() A = [[]] for i in range(N): A.append([0]+LI2()) # print(A) Graph = [[] for _ in range(N+1)] for _ in range(M): u,v = MI() Graph[v].append(u) Graph[u].append(v) UF = UnionFind(7*N) for i in range(1,N+1): for j in range(1,8): x = 7*(i-1)+j if A[i][j] == 1: for k in Graph[i]: if A[k][j] == 1: UF.unite(x,7*(k-1)+j) for i in range(1,N+1): for j in range(1,7): x = 7*(i-1)+j if A[i][j] == A[i][j+1] == 1: UF.unite(x,7*(i-1)+j+1) if A[i][1] == A[i][7] == 1: UF.unite(7*(i-1)+1,7*(i-1)+7) for _ in range(Q): r,x,y = MI() if r == 1: A[x][y] = 1 if 1 < y < 7: if A[x][y-1] == 1: UF.unite(7*(x-1)+y,7*(x-1)+y-1) if A[x][y+1] == 1: UF.unite(7*(x-1)+y,7*(x-1)+y+1) elif y == 1: if A[x][y+1] == 1: UF.unite(7*(x-1)+y,7*(x-1)+y+1) if A[x][7] == 1: UF.unite(7*(x-1)+y,7*(x-1)+7) elif y == 7: if A[x][y-1] == 1: UF.unite(7*(x-1)+y,7*(x-1)+y-1) if A[x][1] == 1: UF.unite(7*(x-1)+y,7*(x-1)+1) for k in Graph[x]: if A[k][y] == 1: UF.unite(7*(x-1)+y,7*(k-1)+y) else: print(UF.X[UF.find(7*(x-1)+1)])