結果

問題 No.86 TVザッピング(2)
ユーザー mamekinmamekin
提出日時 2015-01-17 18:29:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,608 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 91,996 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 14:59:27
合計ジャッジ時間 2,056 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:80:20: warning: ‘sx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         ok |= solve(s, n, sy, sx, i);
               ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:80:20: warning: ‘sy’ may be used uninitialized in this function [-Wmaybe-uninitialized]

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

bool solve(vector<string> s, int n, int sy, int sx, int d)
{
    int y = sy;
    int x = sx;
    int cnt = 0;
    for(int i=0; i<n; ++i){
        int k = 0;
        int d2, y2, x2;
        while(k < 3){
            d2 = (d + 3 + k) % 4;
            y2 = y + dy[d2];
            x2 = x + dx[d2];
            if(s[y2][x2] == '.')
                break;
            ++ k;
        }
        if(k == 3)
            return false;

        if(k == 0){
            ++ cnt;
            if(cnt > 1)
                return false;
        }
        d = d2;
        y = y2;
        x = x2;
        s[y][x] = '#';
    }

    return y == sy && x == sx;
}

int main()
{
    int h, w;
    cin >> h >> w;

    vector<string> s(h+2, string(w+2, '#'));
    int n = 0;
    int sy, sx;
    for(int y=1; y<=h; ++y){
        for(int x=1; x<=w; ++x){
            cin >> s[y][x];
            if(s[y][x] == '.'){
                ++ n;
                sy = y;
                sx = x;
            }
        }
    }

    bool ok = false;
    for(int i=0; i<4; ++i)
        ok |= solve(s, n, sy, sx, i);
    if(ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}
0