結果

問題 No.86 TVザッピング(2)
ユーザー tnodinotnodino
提出日時 2022-03-05 21:00:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,475 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 11,236 KB
実行使用メモリ 8,788 KB
最終ジャッジ日時 2023-09-27 09:19:13
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 15 ms
8,600 KB
testcase_02 AC 16 ms
8,704 KB
testcase_03 AC 16 ms
8,576 KB
testcase_04 AC 14 ms
8,516 KB
testcase_05 AC 15 ms
8,544 KB
testcase_06 AC 15 ms
8,528 KB
testcase_07 AC 16 ms
8,540 KB
testcase_08 AC 25 ms
8,784 KB
testcase_09 AC 26 ms
8,676 KB
testcase_10 AC 25 ms
8,652 KB
testcase_11 AC 15 ms
8,596 KB
testcase_12 AC 15 ms
8,552 KB
testcase_13 AC 14 ms
8,524 KB
testcase_14 AC 24 ms
8,620 KB
testcase_15 AC 24 ms
8,612 KB
testcase_16 AC 24 ms
8,616 KB
testcase_17 WA -
testcase_18 AC 15 ms
8,692 KB
testcase_19 AC 16 ms
8,672 KB
testcase_20 AC 15 ms
8,536 KB
testcase_21 AC 319 ms
8,788 KB
testcase_22 AC 15 ms
8,520 KB
testcase_23 AC 26 ms
8,668 KB
testcase_24 AC 16 ms
8,548 KB
testcase_25 AC 16 ms
8,520 KB
testcase_26 AC 17 ms
8,532 KB
testcase_27 AC 17 ms
8,596 KB
testcase_28 AC 17 ms
8,536 KB
testcase_29 AC 29 ms
8,756 KB
testcase_30 AC 16 ms
8,588 KB
testcase_31 AC 16 ms
8,612 KB
testcase_32 AC 15 ms
8,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def CheckPoint(N, M, L):
    P = []
    dx = [0, 0, 1, 1]
    dy = [0, 1, 0, 1]
    for x in range(N+1):
        for y in range(M+1):
            C = []
            flg = [False] * 4
            cnt = 0
            for i in range(4):
                nx,my = x + dx[i], y + dy[i]
                if L[nx][my] == '.':
                    C.append((nx, my))
                    flg[i] = True
                    cnt += 1
            if cnt % 2 == 0:
                continue
            if cnt == 1:
                X = C[0]
            elif cnt == 3:
                if flg[0] and flg[1] and flg[2]:
                    X = C[0]
                elif flg[0] and flg[1] and flg[3]:
                    X = C[1]
                elif flg[0] and flg[2] and flg[3]:
                    X = C[1]
                elif flg[1] and flg[2] and flg[3]:
                    X = C[2]
            if not X in P:
                P.append(X)
    return P

def Check4(L, P):
    def dfs(x, y, gx, gy, dx, dy):
        if x == gx and y == gy:
            return
        if L[x][y] == '#':
            print('NO')
            exit()
        L[x][y] = '#'
        dfs(x + dx, y + dy, gx, gy, dx, dy)
    X,Y = [list(i) for i in zip(*P)]
    dfs(X[0], Y[0], X[2], Y[2],  1,  0)
    dfs(X[2], Y[2], X[3], Y[3],  0,  1)
    dfs(X[3], Y[3], X[1], Y[1], -1,  0)
    dfs(X[1], Y[1], X[0], Y[0],  0, -1)
    return L

def Check6(L, P):
    def dfs(x, y, gx, gy, dx, dy):
        if x == gx and y == gy:
            return
        if L[x][y] == '#':
            print('NO')
            exit()
        L[x][y] = '#'
        dfs(x + dx, y + dy, gx, gy, dx, dy)
    X,Y = [list(i) for i in zip(*P)]
    dfs(X[2], Y[2], X[1], Y[1], -1,  0)
    dfs(X[1], Y[1], X[0], Y[0],  0, -1)
    dfs(X[0], Y[0], X[4], Y[4],  1,  0)
    dfs(X[4], Y[4], X[5], Y[5],  0,  1)
    dfs(X[5], Y[5], X[3], Y[3], -1,  0)
    dfs(X[3], Y[3], X[2], Y[2],  0, -1)
    return L

def CheckDots(N, M, L):
    for x in range(N+1):
        for y in range(M+1):
            if L[x][y] == '.':
                return False
    return True

N,M = map(int,input().split())
A = [list(input()) for _ in range(N)]
B = [['#'] * (M+2) for _ in range(N+2)]
for i in range(N):
    for j in range(M):
        B[i+1][j+1] = A[i][j]
P = CheckPoint(N, M, B)
if len(P) != 4 and len(P) != 6:
    print('NO')
    exit()
if len(P) == 4:
    B = Check4(B, P)
elif len(P) == 6:
    B = Check6(B, P)
if CheckDots(N, M, B):
    print('YES')
else:
    print('NO')
0