結果

問題 No.86 TVザッピング(2)
ユーザー koyoprokoyopro
提出日時 2015-10-01 18:26:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 2,592 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 148,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 15:02:09
合計ジャッジ時間 2,261 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define REP(i, n) for(int i=0; i<(n); i++)

int N,M;
char b[111][111];
struct pos { int x, y; pos(int _x, int _y) { x = _x; y = _y; } };
int dxy[] = {0, 1, 0, -1, 0};
int total = 0; // 押せるボタンの数
bool isok(int y, int x) {
    vector<pos> afs;
    REP(i,4) {
        int nx = x + dxy[i];
        int ny = y + dxy[i+1];
        if (nx<0||M<=nx||ny<0||N<=ny) continue;
        afs.push_back(pos(nx,ny));
    }
    for (pos a : afs) {
        // 4方向チェック
        pos pre = pos(x,y);
        pos p = a;
        int cnt = 0;
        while (true) {
            cnt++;
            if (cnt > total) break; // ループしてそう
            if (p.x == x && p.y == y) {
                // 戻ってきた
                break;
            }
            int dx = p.x - pre.x;
            int dy = p.y - pre.y;
            int nx = p.x + dx;
            int ny = p.y + dy;
            bool straight = true;
            if (nx<0||M<=nx||ny<0||N<=ny) straight = false;
            if (b[ny][nx] == '#') straight = false;

            // 右を見てみる
            int rdx = -1 * dy;
            int rdy = dx;
            int rnx = p.x + rdx;
            int rny = p.y + rdy;
            if (!(rnx<0||M<=rnx||rny<0||N<=rny)) {
                if (b[rny][rnx] == '.') {
                    // 右に行けるところがあるとダメ
                    break;
                }
            }
            
            if (straight) {
                // まっすぐ
                pre = p;
                p = pos(nx,ny);
            } else {
                // 左回転
                int ldx = dy;
                int ldy = -1 * dx;
                nx = p.x + ldx;
                ny = p.y + ldy;
                straight = true;
                if (nx<0||M<=nx||ny<0||N<=ny) straight = false;
                if (b[ny][nx] == '#') straight = false;
                if (!straight) break; // 行くところない
                // 左行ける
                pre = p;
                p = pos(nx,ny);
            }
        }
        if (total == cnt) return true;
    }
    return false;
}
signed main()
{
    cin>>N>>M;
    string s;
    REP(y,N) {
        cin>>s;
        REP(x,M) {
            b[y][x] = s[x];
        }
    }
    bool ok = false;
    REP(x,M) REP(y,N) total += (b[y][x] == '.');
    REP(x,M) REP(y,N) {
        char c = b[y][x];
        if (c == '#') continue;
        if (isok(y,x)) {
            ok = true;
            break;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}
0