結果
問題 | No.86 TVザッピング(2) |
ユーザー |
![]() |
提出日時 | 2015-07-23 17:53:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,252 ms / 5,000 ms |
コード長 | 2,658 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 90,660 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 13:59:04 |
合計ジャッジ時間 | 2,868 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> //#include<cctype> #include<climits> #include<iostream> #include<string> #include<vector> #include<map> //#include<list> #include<queue> #include<deque> #include<algorithm> //#include<numeric> #include<utility> #include<complex> //#include<memory> #include<functional> #include<cassert> #include<set> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef complex<double> C; const int MAXN = 104; string field[MAXN]; bool used[MAXN][MAXN]; int N, M; int lasty, lastx, lastdir; bool outOfRange(int y, int x) { return (y < 0 || y >= N || x < 0 || x >= M); } void dfs(int y, int x, int dir, int flag) { lasty = y; lastx = x; lastdir = dir; used[y][x] = true; int ny = y+dy[dir]; int nx = x+dx[dir]; if (outOfRange(ny, nx) || field[ny][nx] == '#' || used[ny][nx]) { dir += (flag == 0) ? 1 : 3; dir %= 4; ny = y+dy[dir]; nx = x+dx[dir]; if (outOfRange(ny, nx) || field[ny][nx] == '#') return; if (used[ny][nx]) return; dfs(ny, nx, dir, flag); return; } dfs(ny, nx, dir, flag); } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; for (int i = 0; i < N; i++) cin >> field[i]; for (int y = 0; y < N; y++) for (int x = 0; x < M; x++) { if (field[y][x] == '#') continue; for (int k = 0; k < 4; k++) { for (int flag = 0; flag < 2; flag++) { memset(used, false, sizeof(used)); dfs(y, x, k, flag); bool ng = false; for (int i = 0; i < N; i++) { if (ng) break; for (int j = 0; j < M; j++) { if (field[i][j] != '#' && !used[i][j]) { ng = true; break; } } } if (!ng) { if (lasty+dy[lastdir] == y && lastx+dx[lastdir] == x) { cout << "YES" << endl; return 0; } int dirdir = lastdir; dirdir += (flag == 0) ? 1 : 3; dirdir %= 4; if (lasty+dy[dirdir] == y && lastx+dx[dirdir] == x) { cout << "YES" << endl; return 0; } } } } } cout << "NO" << endl; return 0; }