結果

問題 No.86 TVザッピング(2)
ユーザー 👑 colognecologne
提出日時 2022-01-27 15:04:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,367 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 76,908 KB
最終ジャッジ日時 2023-08-26 15:22:16
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,420 KB
testcase_01 AC 74 ms
71,300 KB
testcase_02 AC 71 ms
71,416 KB
testcase_03 WA -
testcase_04 AC 71 ms
71,412 KB
testcase_05 AC 71 ms
71,236 KB
testcase_06 WA -
testcase_07 AC 71 ms
71,400 KB
testcase_08 WA -
testcase_09 AC 83 ms
76,088 KB
testcase_10 AC 83 ms
76,440 KB
testcase_11 AC 70 ms
71,088 KB
testcase_12 AC 72 ms
71,616 KB
testcase_13 AC 71 ms
71,556 KB
testcase_14 WA -
testcase_15 AC 82 ms
76,492 KB
testcase_16 AC 84 ms
76,352 KB
testcase_17 WA -
testcase_18 AC 75 ms
75,700 KB
testcase_19 AC 75 ms
75,632 KB
testcase_20 AC 71 ms
71,412 KB
testcase_21 AC 83 ms
76,648 KB
testcase_22 AC 71 ms
71,344 KB
testcase_23 AC 80 ms
75,924 KB
testcase_24 AC 72 ms
71,356 KB
testcase_25 AC 72 ms
71,160 KB
testcase_26 AC 72 ms
71,524 KB
testcase_27 WA -
testcase_28 AC 71 ms
71,396 KB
testcase_29 AC 84 ms
76,476 KB
testcase_30 AC 72 ms
71,512 KB
testcase_31 AC 71 ms
71,160 KB
testcase_32 AC 73 ms
71,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math


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


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

    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 False

    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 == mini:
                    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