結果

問題 No.86 TVザッピング(2)
ユーザー 👑 rin204rin204
提出日時 2023-02-17 16:07:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 625 ms / 5,000 ms
コード長 1,207 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 78,280 KB
最終ジャッジ日時 2023-09-26 15:00:19
合計ジャッジ時間 6,310 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,524 KB
testcase_01 AC 65 ms
71,280 KB
testcase_02 AC 67 ms
71,204 KB
testcase_03 AC 67 ms
71,136 KB
testcase_04 AC 65 ms
71,072 KB
testcase_05 AC 66 ms
71,168 KB
testcase_06 AC 67 ms
71,080 KB
testcase_07 AC 70 ms
71,288 KB
testcase_08 AC 70 ms
71,344 KB
testcase_09 AC 218 ms
77,548 KB
testcase_10 AC 625 ms
78,280 KB
testcase_11 AC 72 ms
76,132 KB
testcase_12 AC 66 ms
71,224 KB
testcase_13 AC 69 ms
71,012 KB
testcase_14 AC 81 ms
76,108 KB
testcase_15 AC 90 ms
76,480 KB
testcase_16 AC 94 ms
76,952 KB
testcase_17 AC 73 ms
71,164 KB
testcase_18 AC 79 ms
76,064 KB
testcase_19 AC 76 ms
76,092 KB
testcase_20 AC 73 ms
75,724 KB
testcase_21 AC 570 ms
78,004 KB
testcase_22 AC 67 ms
71,084 KB
testcase_23 AC 86 ms
76,328 KB
testcase_24 AC 70 ms
71,228 KB
testcase_25 AC 72 ms
71,352 KB
testcase_26 AC 70 ms
71,004 KB
testcase_27 AC 69 ms
71,136 KB
testcase_28 AC 68 ms
71,008 KB
testcase_29 AC 83 ms
76,692 KB
testcase_30 AC 68 ms
71,296 KB
testcase_31 AC 71 ms
71,152 KB
testcase_32 AC 68 ms
71,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w = map(int, input().split())
S = ["#" * (w + 2)] + ["#" + input() + "#" for _ in range(h)] + ["#" * (w + 2)]
used = [[False] * (w + 2) for _ in range(h + 2)]
cc = sum(row.count('.') for row in S)

di = [0, -1, 0, 1]
dj = [1, 0, -1, 0]

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if S[i][j] == '#':
            continue
        
        for k in range(4):
            lst = []
            ii = i
            jj = j
            cnt = 0
            t = k
            while not used[ii][jj]:
                cnt += 1
                used[ii][jj] = True
                lst.append((ii, jj))
                ni = ii + di[t]
                nj = jj + dj[t]
                if S[ni][nj] == '.':
                    ii, jj = ni, nj
                    continue
                t = (t + 1) % 4
                ni = ii + di[t]
                nj = jj + dj[t]
                if S[ni][nj] == '.':
                    ii, jj = ni, nj
                    continue
                else:
                    break

            if cnt == cc and ii == i and jj == j:
                print("YES")
                exit()

            for ii, jj in lst:
                used[ii][jj] = False

print("NO")
0