結果

問題 No.86 TVザッピング(2)
ユーザー 👑 colognecologne
提出日時 2022-01-27 14:41:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,186 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 76,044 KB
最終ジャッジ日時 2023-08-26 14:43:00
合計ジャッジ時間 4,089 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,324 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 65 ms
71,416 KB
testcase_04 AC 68 ms
71,492 KB
testcase_05 AC 70 ms
71,664 KB
testcase_06 AC 65 ms
71,664 KB
testcase_07 AC 67 ms
71,332 KB
testcase_08 AC 70 ms
75,720 KB
testcase_09 AC 73 ms
76,028 KB
testcase_10 AC 72 ms
75,852 KB
testcase_11 AC 67 ms
71,544 KB
testcase_12 WA -
testcase_13 AC 67 ms
71,260 KB
testcase_14 AC 75 ms
75,732 KB
testcase_15 AC 72 ms
75,576 KB
testcase_16 AC 71 ms
75,496 KB
testcase_17 AC 67 ms
71,260 KB
testcase_18 AC 66 ms
71,412 KB
testcase_19 AC 67 ms
71,324 KB
testcase_20 AC 67 ms
71,372 KB
testcase_21 AC 73 ms
75,752 KB
testcase_22 AC 67 ms
71,260 KB
testcase_23 AC 74 ms
75,844 KB
testcase_24 AC 67 ms
71,432 KB
testcase_25 AC 66 ms
71,412 KB
testcase_26 WA -
testcase_27 AC 65 ms
71,476 KB
testcase_28 AC 66 ms
71,328 KB
testcase_29 AC 73 ms
76,044 KB
testcase_30 AC 67 ms
71,108 KB
testcase_31 AC 65 ms
71,272 KB
testcase_32 AC 67 ms
71,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math


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


def main():
    N, M = map(int, input().split())
    A = [input() for i in range(N)]

    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 cnt != 2*(maxi-mini) + 2*(maxj-minj):
        print('NO')
        return

    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():
        print('YES')
        return

    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:
            redi = i
        if cnt < 2:
            print('NO')
            return

    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:
            redj = j
        if cnt < 2:
            print('NO')
            return

    if redi is None or redj is None:
        print('NO')
        return

    def checku():
        for i in range(mini, redi+1):
            if A[i][redj] == '#':
                return False
        return True

    def checkd():
        for i in range(redi, maxi+1):
            if A[i][redj] == '#':
                return False
        return True

    def checkl():
        for j in range(minj, redj+1):
            if A[redi][j] == '#':
                return False
        return True

    def checkr():
        for j in range(redj, maxj+1):
            if A[redi][j] == '#':
                return False
            return True

    if (checku() or checkd()) and (checkl() or checkr()):
        print('YES')
    else:
        print('NO')


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