結果
問題 | No.2696 Sign Creation |
ユーザー | hato336 |
提出日時 | 2024-03-22 22:56:12 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,819 bytes |
コンパイル時間 | 313 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 126,276 KB |
最終ジャッジ日時 | 2024-05-17 18:17:51 |
合計ジャッジ時間 | 16,468 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 141 ms
96,752 KB |
testcase_01 | AC | 141 ms
89,672 KB |
testcase_02 | AC | 136 ms
89,184 KB |
testcase_03 | AC | 141 ms
89,664 KB |
testcase_04 | AC | 139 ms
89,336 KB |
testcase_05 | AC | 144 ms
90,120 KB |
testcase_06 | AC | 138 ms
89,356 KB |
testcase_07 | AC | 141 ms
89,252 KB |
testcase_08 | AC | 190 ms
90,592 KB |
testcase_09 | AC | 148 ms
90,052 KB |
testcase_10 | AC | 198 ms
90,928 KB |
testcase_11 | AC | 157 ms
89,988 KB |
testcase_12 | AC | 161 ms
89,984 KB |
testcase_13 | AC | 987 ms
102,068 KB |
testcase_14 | AC | 512 ms
102,728 KB |
testcase_15 | AC | 478 ms
102,344 KB |
testcase_16 | AC | 981 ms
102,364 KB |
testcase_17 | AC | 410 ms
90,324 KB |
testcase_18 | AC | 314 ms
91,528 KB |
testcase_19 | AC | 548 ms
96,684 KB |
testcase_20 | AC | 172 ms
90,100 KB |
testcase_21 | AC | 463 ms
103,984 KB |
testcase_22 | AC | 483 ms
91,112 KB |
testcase_23 | AC | 484 ms
100,424 KB |
testcase_24 | AC | 476 ms
100,340 KB |
testcase_25 | AC | 610 ms
95,468 KB |
testcase_26 | AC | 405 ms
90,712 KB |
testcase_27 | AC | 468 ms
90,560 KB |
testcase_28 | AC | 398 ms
91,072 KB |
testcase_29 | AC | 465 ms
90,208 KB |
testcase_30 | AC | 410 ms
90,280 KB |
testcase_31 | TLE | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = collections.defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items()) #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) input = sys.stdin.readline #n = int(input()) #alist = list(map(int,input().split())) #alist = [] #s = input() h,w,n,d = map(int,input().split()) #for i in range(n): # alist.append(list(map(int,input().split()))) dxy = [] for x in range(-5,6): for y in range(-5,6): if 1 <= abs(x) + abs(y) <= d: dxy.append((x,y)) s = set() c = collections.defaultdict(int) l = [] for i in range(n): x,y =map(int,input().split()) x -= 1 y -= 1 s.add((x,y)) l.append((x,y)) c[(x,y)] = i uf = UnionFind(n) for i in range(n): x,y = l[i] for dx,dy in dxy: if (x+dx,y+dy) in s: uf.union(i,c[(x+dx,y+dy)]) mi,ma = 10**18,-10**18 res = 0 for i in range(n): if uf.find(i) == i and uf.size(i) >= 2: res += 1 for i in range(h): for j in range(w): if (i,j) in s: continue se = set() now = res cnt = 0 for dx,dy in dxy: if (i+dx,j+dy) in s and uf.find(c[i+dx,j+dy]) not in se: se.add(uf.find(c[i+dx,j+dy])) if cnt == 0: cnt += 1 if uf.size(c[i+dx,j+dy]) == 1: now += 1 else: if uf.size(c[i+dx,j+dy]) >= 2: now -= 1 mi = min(mi,now) ma = max(ma,now) #print(i,j,res,se) print(mi,ma)