結果

問題 No.86 TVザッピング(2)
ユーザー koyoprokoyopro
提出日時 2015-10-01 18:19:33
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,433 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 148,564 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-27 01:13:49
合計ジャッジ時間 6,124 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

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

int N,M;
string b[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 {
                // 左回転
                swap(dx, dy);
                dy *= -1;
                nx = p.x + dx;
                ny = p.y + dy;
                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;
    REP(i,N) cin>>b[i];
    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