結果
問題 | No.424 立体迷路 |
ユーザー | NatsubiSogan |
提出日時 | 2021-02-04 03:09:13 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,450 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 10,836 KB |
実行使用メモリ | 8,220 KB |
最終ジャッジ日時 | 2023-09-12 22:22:58 |
合計ジャッジ時間 | 2,174 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
8,152 KB |
testcase_01 | AC | 17 ms
8,100 KB |
testcase_02 | AC | 16 ms
8,052 KB |
testcase_03 | AC | 16 ms
8,116 KB |
testcase_04 | AC | 17 ms
8,220 KB |
testcase_05 | AC | 16 ms
8,080 KB |
testcase_06 | AC | 17 ms
8,220 KB |
testcase_07 | AC | 16 ms
8,160 KB |
testcase_08 | AC | 16 ms
8,060 KB |
testcase_09 | AC | 17 ms
8,020 KB |
testcase_10 | AC | 16 ms
8,100 KB |
testcase_11 | AC | 17 ms
8,128 KB |
testcase_12 | AC | 17 ms
8,052 KB |
testcase_13 | AC | 17 ms
8,216 KB |
testcase_14 | AC | 17 ms
8,156 KB |
testcase_15 | AC | 17 ms
8,060 KB |
testcase_16 | AC | 17 ms
8,112 KB |
testcase_17 | AC | 22 ms
8,100 KB |
testcase_18 | AC | 21 ms
8,104 KB |
testcase_19 | AC | 22 ms
8,100 KB |
testcase_20 | AC | 22 ms
8,104 KB |
testcase_21 | AC | 17 ms
8,056 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 27 ms
8,072 KB |
testcase_25 | AC | 27 ms
8,084 KB |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.par = list(range(self.n)) self.rank = [1] * n self.count = n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): p = self.find(x) q = self.find(y) if p == q: return None if p > q: p, q = q, p self.rank[p] += self.rank[q] self.par[q] = p self.count -= 1 def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return self.rank[x] def count(self): return self.count h, w = map(int, input().split()) sx, sy, gx, gy = map(int, input().split()) s = [list(map(int, list(input()))) for i in range(h)] UF = UnionFind(h * w) for i in range(h): for j in range(w - 1): if abs(s[i][j] - s[i][j + 1]) <= 1: UF.unite(i * w + j, i * w + j + 1) if j != w - 2 and s[i][j] == s[i][j + 2]: UF.unite(i * w + j, i * w + j + 2) for i in range(h - 1): for j in range(w): if abs(s[i][j] - s[i + 1][j]) <= 1: UF.unite(i * w + j, (i + 1) * w + j) if i != h - 2 and s[i][j] == s[i + 2][j]: UF.unite(i * w + j, (i + 2) * w + j) print("YES" if UF.same((sx - 1) * w + (sy - 1), (gx - 1) * w + (gy - 1)) else "NO")