結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2015-07-23 17:29:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,445 bytes |
| コンパイル時間 | 734 ms |
| コンパイル使用メモリ | 88,492 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-20 13:59:01 |
| 合計ジャッジ時間 | 3,404 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 2 |
ソースコード
#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;
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;
//cout << y << " " << x << endl;
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) {
for (int l = 0; l < 4; l++) {
if (lasty+dy[l] == y && lastx+dx[l] == x) {
cout << "YES" << endl;
return 0;
}
}
}
}
}
}
cout << "NO" << endl;
return 0;
}
mayoko_