結果
問題 | No.86 TVザッピング(2) |
ユーザー |
|
提出日時 | 2015-01-17 18:29:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,608 bytes |
コンパイル時間 | 757 ms |
コンパイル使用メモリ | 100,008 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 13:58:08 |
合計ジャッジ時間 | 1,643 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:80:20: warning: ‘sy’ may be used uninitialized [-Wmaybe-uninitialized] 80 | ok |= solve(s, n, sy, sx, i); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:66:9: note: ‘sy’ was declared here 66 | int sy, sx; | ^~ main.cpp:80:20: warning: ‘sx’ may be used uninitialized [-Wmaybe-uninitialized] 80 | ok |= solve(s, n, sy, sx, i); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:66:13: note: ‘sx’ was declared here 66 | int sy, sx; | ^~
ソースコード
#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; }