結果

問題 No.86 TVザッピング(2)
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-12 18:50:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 1,808 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 168,172 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 15:03:47
合計ジャッジ時間 3,318 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 41 ms
4,380 KB
testcase_09 AC 61 ms
4,380 KB
testcase_10 AC 88 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 41 ms
4,376 KB
testcase_15 AC 43 ms
4,376 KB
testcase_16 AC 40 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 105 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 39 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 43 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M;
    string A[110];
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int total = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            total += (A[i][j] == '.');
        }
    }

    const int dx[] = {1, 0, -1, 0};
    const int dy[] = {0, 1, 0, -1};

    bool ans = false;

    auto ok_x = [&](int x) {
        return x >= 0 && x < N;
    };
    auto ok_y = [&](int y) {
        return y >= 0 && y < M;
    };
    auto ok = [&](int x, int y) {
        return ok_x(x) && ok_y(y) && A[x][y] == '.';
    };

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            for (int start_dir = 0; start_dir < 4; start_dir++) {
                int x = i, y = j, dir = start_dir;
                int seen[110][110] = {};
                for (int cnt = 1; cnt <= (N + M) * 2; cnt++) {
                    seen[x][y] = 1;
                    if (ok(x + dx[dir], y + dy[dir])) {
                        x += dx[dir];
                        y += dy[dir];
                    } else {
                        (++dir) %= 4;
                        if (ok(x + dx[dir], y + dy[dir])) {
                            x += dx[dir];
                            y += dy[dir];
                        } else {
                            break;
                        }
                    }
                    if (i == x && j == y) {
                        if (cnt == total)
                            ans = true;
                        else
                            break;
                    }
                    if (seen[x][y])
                        break;
                }
            }
        }
    }

    cout << (ans ? "YES" : "NO") << endl;
}
0