結果

問題 No.86 TVザッピング(2)
ユーザー 👑 colognecologne
提出日時 2022-01-27 14:42:28
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 2,354 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 75,732 KB
最終ジャッジ日時 2023-08-26 14:43:59
合計ジャッジ時間 4,003 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 65 ms
70,716 KB
testcase_02 AC 67 ms
71,176 KB
testcase_03 AC 67 ms
71,096 KB
testcase_04 AC 67 ms
70,856 KB
testcase_05 WA -
testcase_06 AC 66 ms
71,172 KB
testcase_07 AC 68 ms
71,168 KB
testcase_08 AC 70 ms
75,420 KB
testcase_09 AC 72 ms
75,376 KB
testcase_10 AC 70 ms
75,516 KB
testcase_11 AC 67 ms
70,856 KB
testcase_12 WA -
testcase_13 AC 66 ms
71,076 KB
testcase_14 WA -
testcase_15 AC 70 ms
75,116 KB
testcase_16 AC 69 ms
74,896 KB
testcase_17 WA -
testcase_18 AC 66 ms
71,016 KB
testcase_19 AC 67 ms
71,100 KB
testcase_20 AC 68 ms
71,244 KB
testcase_21 AC 73 ms
75,732 KB
testcase_22 AC 67 ms
71,252 KB
testcase_23 WA -
testcase_24 AC 67 ms
71,116 KB
testcase_25 AC 67 ms
71,248 KB
testcase_26 WA -
testcase_27 AC 67 ms
71,172 KB
testcase_28 AC 69 ms
71,096 KB
testcase_29 AC 73 ms
75,268 KB
testcase_30 AC 69 ms
70,848 KB
testcase_31 WA -
testcase_32 AC 68 ms
71,164 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 redi is not None:
                print('NO')
                return
        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:
            if redj is not None:
                print('NO')
                return
            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