結果
| 問題 |
No.179 塗り分け
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-02 11:40:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 3,000 ms |
| コード長 | 1,469 bytes |
| コンパイル時間 | 395 ms |
| コンパイル使用メモリ | 82,496 KB |
| 実行使用メモリ | 77,220 KB |
| 最終ジャッジ日時 | 2024-09-30 23:09:09 |
| 合計ジャッジ時間 | 4,371 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 40 |
ソースコード
import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]
def main():
H, W = NMI()
S = [SI() for _ in range(H)]
B = []
D = {}
cnt = 0
for h in range(H):
for w in range(W):
if S[h][w] == "#":
B.append((h, w))
D[(h, w)] = cnt
cnt += 1
if len(B) % 2:
print("NO")
return
for i in range(1, len(B)):
used = [0] * len(B)
hi, wi = B[i]
h0, w0 = B[0]
gh, gw = hi-h0, wi-w0
ok = True
for j in range(len(B)):
if used[j]:
continue
used[j] = 1
h, w = B[j]
nh, nw = h+gh, w+gw
if (nh, nw) in D:
used[D[(nh, nw)]] = 1
else:
ok = False
break
# print(used)
if ok:
print("YES")
return
print("NO")
if __name__ == "__main__":
main()