結果
問題 | No.2696 Sign Creation |
ユーザー | miya145592 |
提出日時 | 2024-03-22 23:40:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,026 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 102,384 KB |
最終ジャッジ日時 | 2024-05-17 18:21:11 |
合計ジャッジ時間 | 5,993 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
55,016 KB |
testcase_01 | AC | 35 ms
53,728 KB |
testcase_02 | AC | 36 ms
54,096 KB |
testcase_03 | AC | 36 ms
54,604 KB |
testcase_04 | AC | 37 ms
54,604 KB |
testcase_05 | AC | 36 ms
53,456 KB |
testcase_06 | AC | 35 ms
53,612 KB |
testcase_07 | AC | 34 ms
53,924 KB |
testcase_08 | AC | 101 ms
77,124 KB |
testcase_09 | AC | 37 ms
53,468 KB |
testcase_10 | AC | 107 ms
77,644 KB |
testcase_11 | AC | 40 ms
59,960 KB |
testcase_12 | AC | 40 ms
59,544 KB |
testcase_13 | AC | 411 ms
96,752 KB |
testcase_14 | AC | 283 ms
93,748 KB |
testcase_15 | AC | 274 ms
93,704 KB |
testcase_16 | AC | 385 ms
92,248 KB |
testcase_17 | AC | 44 ms
63,232 KB |
testcase_18 | AC | 123 ms
81,096 KB |
testcase_19 | AC | 239 ms
93,676 KB |
testcase_20 | AC | 42 ms
62,116 KB |
testcase_21 | AC | 252 ms
89,360 KB |
testcase_22 | AC | 103 ms
78,504 KB |
testcase_23 | AC | 241 ms
85,476 KB |
testcase_24 | AC | 244 ms
85,512 KB |
testcase_25 | AC | 288 ms
96,988 KB |
testcase_26 | AC | 67 ms
79,296 KB |
testcase_27 | AC | 75 ms
79,112 KB |
testcase_28 | AC | 69 ms
79,000 KB |
testcase_29 | AC | 43 ms
64,152 KB |
testcase_30 | AC | 50 ms
68,032 KB |
testcase_31 | AC | 686 ms
102,384 KB |
testcase_32 | AC | 35 ms
53,008 KB |
testcase_33 | AC | 39 ms
59,916 KB |
testcase_34 | AC | 44 ms
63,124 KB |
testcase_35 | AC | 35 ms
54,844 KB |
testcase_36 | AC | 39 ms
53,484 KB |
testcase_37 | AC | 33 ms
53,796 KB |
testcase_38 | AC | 34 ms
53,460 KB |
testcase_39 | AC | 34 ms
54,500 KB |
testcase_40 | WA | - |
ソースコード
class UnionFind: def __init__(self, n, w=None): self.par = [-1]*n self.rank = [0]*n self.siz = [1]*n self.cnt = n self.min_node = [i for i in range(n)] self.weight = w if w else [1]*n def root(self, x): if self.par[x] == -1: return x self.par[x] = self.root(self.par[x]) return self.par[x] def issame(self, x, y): return self.root(x) == self.root(y) def unite(self, x, y): px = self.root(x) py = self.root(y) if px == py: return False if self.rank[px] < self.rank[py]: px, py = py, px self.par[py] = px if self.rank[px] == self.rank[py]: self.rank[px] += 1 self.siz[px] += self.siz[py] self.cnt -= 1 self.min_node[px] = min(self.min_node[px], self.min_node[py]) self.weight[px] += self.weight[py] return False def count(self): return self.cnt def min(self, x): return self.min_node[self.root(x)] def getweight(self, x): return self.weight[self.root(x)] def size(self, x): return self.siz[self.root(x)] import sys input = sys.stdin.readline H, W, N, D = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(N)] field = [[-1 for _ in range(W)] for _ in range(H)] for i in range(N): x, y = XY[i] x-=1 y-=1 field[x][y] = i XY[i] = [x, y] man = set() for i in range(D+1): for j in range(D+1): if i+j<=D: man.add((i, j)) if i!=0: man.add((-i, j)) if j!=0: man.add((i, -j)) if i!=0 and j!=0: man.add((-i, -j)) else: break field2 = [[0 for _ in range(W)] for _ in range(H)] UF = UnionFind(N) for i in range(N): x, y = XY[i] for dx, dy in man: nx = x+dx ny = y+dy if 0<=nx<H and 0<=ny<W: field2[nx][ny] += 1 if field[nx][ny]!=-1: j = field[nx][ny] UF.unite(i, j) max_cnt = 0 for i in range(N): if UF.size(i)==1: x, y = XY[i] for dx, dy in man: nx = x+dx ny = y+dy if 0<=nx<H and 0<=ny<W: if field2[nx][ny]==1 and field[nx][ny]==-1: max_cnt = 1 break if max_cnt==1: break field3 = [[0 for _ in range(W)] for _ in range(H)] S = dict() cnt = 0 for i in range(N): x, y = XY[i] if UF.size(i)==1: cnt+=1 continue r = UF.root(i) if r not in S: S[r] = set() for dx, dy in man: nx = x+dx ny = y+dy if 0<=nx<H and 0<=ny<W and field[nx][ny]==-1: S[r].add((nx, ny)) min_cnt = 0 for r in S: for x, y in S[r]: field3[x][y] += 1 min_cnt = max(min_cnt, field3[x][y]) if min_cnt>0: min_cnt-=1 print(UF.count()-cnt-min_cnt, UF.count()-cnt+max_cnt)