結果

問題 No.86 TVザッピング(2)
ユーザー koyoprokoyopro
提出日時 2015-10-01 18:25:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,531 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 148,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 01:14:25
合計ジャッジ時間 8,306 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 (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