結果

問題 No.86 TVザッピング(2)
ユーザー 👑 colognecologne
提出日時 2022-01-27 15:07:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,409 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 78,924 KB
最終ジャッジ日時 2023-08-26 15:24:53
合計ジャッジ時間 4,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math


def input(): return sys.stdin.readline().rstrip()


def check(A):
    N = len(A)
    M = len(A[0])

    for i in A:
        print(*i, sep='')

    mini = minj = math.inf
    maxi = maxj = -math.inf
    cnt = 0
    for i in range(N):
        for j in range(M):
            if A[i][j] == '.':
                cnt += 1
                mini, minj, maxi, maxj = \
                    min(mini, i), min(minj, j), max(maxi, i), max(maxj, j)

    if maxi == mini or maxj == minj:
        return False

    if cnt != 2*(maxi-mini) + 2*(maxj-minj):
        return False

    def checkrect():
        for i in range(mini, maxi+1):
            if A[i][minj] == '#' or A[i][maxj] == '#':
                return False
        for j in range(minj, maxj+1):
            if A[mini][j] == '#' or A[maxi][j] == '#':
                return False
        return True

    if checkrect():
        return True

    redi = redj = None
    for i in range(mini+1, maxi):
        cnt = 0
        for j in range(minj, maxj+1):
            if A[i][j] == '.':
                cnt += 1
        if cnt > 2:
            if redi is not None:
                return False
            redi = i
        if cnt < 2:
            return False

    for j in range(minj+1, maxj):
        cnt = 0
        for i in range(mini, maxi+1):
            if A[i][j] == '.':
                cnt += 1
        if cnt > 2:
            if redj is not None:
                return False
            redj = j
        if cnt < 2:
            return False

    if redi is None or redj is None:
        return False

    for i in range(N):
        for j in range(M):
            if A[i][j] == '.':
                if i == maxi:
                    continue
                if j == minj:
                    continue
                if i == mini and minj <= j <= redj:
                    continue
                if i == redi and redj <= j <= maxj:
                    continue
                if j == redj and mini <= i <= redi:
                    continue
                if j == maxj and redi <= i <= maxi:
                    continue
                return False
    return True


def main():
    N, M = map(int, input().split())
    A = [input() for i in range(N)]
    for i in range(4):
        if check(A):
            print('YES')
            return
        *A, = zip(*A[::-1])

    print('NO')


if __name__ == '__main__':
    main()
0