結果

問題 No.86 TVザッピング(2)
ユーザー なおなお
提出日時 2014-12-05 01:13:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 727 ms / 5,000 ms
コード長 1,324 bytes
コンパイル時間 1,329 ms
コンパイル使用メモリ 150,128 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 14:57:58
合計ジャッジ時間 3,849 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 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,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 121 ms
4,380 KB
testcase_10 AC 727 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 10 ms
4,384 KB
testcase_16 AC 10 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 199 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 106 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘bool check(int, int, int)’:
main.cpp:11:24: warning: control reaches end of non-void function [-Wreturn-type]
     vector<string> k = m;
                        ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

int H,W,c;
vector<string> m;
const int dir[][2] = {{1,0},{0,-1},{-1,0},{0,1}};

bool check(int cx, int cy, int cd){
    int x = cx, y = cy, d = cd;
    vector<string> k = m;
    int cnt = 0;
    while(cnt < c){
        int mx = x + dir[d][0];
        int my = y + dir[d][1];
        if(mx < 0 || my < 0 || mx >= W || my >= H || k[my][mx] == '#'){
            d = (d+1)%4;
            mx = x + dir[d][0];
            my = y + dir[d][1];
            if(mx < 0 || my < 0 || mx >= W || my >= H || k[my][mx] == '#'){
                return false;
            }
        }
        k[my][mx] = '#';
        cnt++;
        if(mx == cx && my == cy){
            return (c == cnt);
        }
        x = mx, y = my;
    }
}

int main(){
    cin >> H >> W;

    REP(i,H){
        string s;
        cin >> s;
        if(s.size() != W) throw;
        m.push_back(s);
        REP(x,W) if(s[x] == '.') c++;
    }
    if(c == 1) throw;

    REP(y,H) REP(x,W){
        if(m[y][x] != '.') continue;
        REP(d,4){
            if(check(x,y,d)){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}
0