結果
問題 | No.86 TVザッピング(2) |
ユーザー | tnodino |
提出日時 | 2022-03-05 15:22:14 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,914 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 13,556 KB |
最終ジャッジ日時 | 2024-07-19 20:07:52 |
合計ジャッジ時間 | 2,280 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,880 KB |
testcase_01 | AC | 29 ms
10,880 KB |
testcase_02 | AC | 28 ms
11,008 KB |
testcase_03 | AC | 29 ms
10,880 KB |
testcase_04 | AC | 29 ms
10,880 KB |
testcase_05 | AC | 29 ms
11,008 KB |
testcase_06 | AC | 29 ms
11,008 KB |
testcase_07 | AC | 29 ms
10,880 KB |
testcase_08 | AC | 39 ms
11,264 KB |
testcase_09 | AC | 33 ms
11,136 KB |
testcase_10 | AC | 62 ms
13,556 KB |
testcase_11 | AC | 30 ms
10,880 KB |
testcase_12 | AC | 30 ms
11,008 KB |
testcase_13 | AC | 29 ms
11,008 KB |
testcase_14 | AC | 37 ms
11,520 KB |
testcase_15 | AC | 34 ms
11,136 KB |
testcase_16 | AC | 32 ms
11,264 KB |
testcase_17 | AC | 29 ms
11,136 KB |
testcase_18 | AC | 30 ms
11,008 KB |
testcase_19 | AC | 30 ms
11,136 KB |
testcase_20 | AC | 28 ms
10,880 KB |
testcase_21 | AC | 50 ms
12,416 KB |
testcase_22 | AC | 30 ms
10,880 KB |
testcase_23 | AC | 39 ms
11,264 KB |
testcase_24 | WA | - |
testcase_25 | AC | 29 ms
11,008 KB |
testcase_26 | AC | 29 ms
10,880 KB |
testcase_27 | AC | 28 ms
10,880 KB |
testcase_28 | AC | 29 ms
11,136 KB |
testcase_29 | AC | 32 ms
11,136 KB |
testcase_30 | AC | 29 ms
11,136 KB |
testcase_31 | WA | - |
testcase_32 | AC | 28 ms
11,136 KB |
ソースコード
from sys import setrecursionlimit setrecursionlimit(10**6) from copy import deepcopy def Check1(N, M, A): def dfs(x, y, rx, ry): for i in range(4): nx = x + dx[i] my = y + dy[i] if nx < 0 or N <= nx or my < 0 or M <= my: continue if nx == rx and my == ry: continue if L[nx][my] == '#': continue L[nx][my] = '#' dfs(nx, my, x, y) L = deepcopy(A) flg = False for i in range(N): for j in range(M): if L[i][j] == '.': if flg: print('NO') exit() dfs(i, j, -1, -1) flg = True def Check2(N, M, A): def Count(x, y): ret = 0 for i in range(4): nx = x + dx[i] my = y + dy[i] if nx < 0 or N <= nx or my < 0 or M <= my: continue if A[nx][my] == '.': ret += 1 return ret cnt = [[0] * M for _ in range(N)] for i in range(N): for j in range(M): if A[i][j] == '.': cnt[i][j] = Count(i, j) if cnt[i][j] == 1: print('NO') exit() cnt[i][j] -= 2 return cnt def Check3(N, M, cnt): def dfs(x, y, rx, ry): for i in range(4): nx = x + dx[i] my = y + dy[i] if nx < 0 or N <= nx or my < 0 or M <= my: continue if nx == rx and my == ry: continue if L[nx][my] == 0: continue L[nx][my] = 0 dfs(nx, my, x, y) L = deepcopy(cnt) flg = False for i in range(N): for j in range(M): if L[i][j] > 0: if flg: print('NO') exit() dfs(i, j, -1, -1) flg = True def Check4(N, M, cnt): flg = False for i in range(N): for j in range(M): if cnt[i][j] == 2: if flg: print('NO') exit() flg = True def Check5(N, M, cnt): def dfs(x, y): ret = 0 for i in range(4): nx = x + dx[i] my = y + dy[i] if nx < 0 or N <= nx or my < 0 or M <= my: continue ret += cnt[nx][my] return ret for i in range(N): for j in range(M): if cnt[i][j] == 2: if dfs(i, j) == 4: print('NO') exit() N,M = map(int,input().split()) A = [list(input()) for _ in range(N)] if N == 1 or M == 1: print('NO') exit() dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] Check1(N, M, A) cnt = Check2(N, M, A) Check3(N, M, cnt) Check4(N, M, cnt) Check5(N, M, cnt) print('YES')