結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
hotpepsi
|
| 提出日時 | 2014-12-05 00:39:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 672 ms / 5,000 ms |
| コード長 | 1,445 bytes |
| コンパイル時間 | 750 ms |
| コンパイル使用メモリ | 79,912 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:57:09 |
| 合計ジャッジ時間 | 2,671 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef vector<string> StrVec;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
bool check(int N, int M, StrVec v, int total, int sx, int sy, int dir)
{
int x = sx, y = sy;
while (true) {
int i;
for (i = 0; i < 2; ++i) {
int nd = (dir + i) % 4;
int nx = x + dx[nd], ny = y + dy[nd];
if (v[ny][nx] == '.') {
dir = nd, --total;
x = nx, y = ny;
v[y][x] = '#';
break;
}
}
if (i >= 2) {
break;
}
}
return x == sx && y == sy && total == 0;
}
bool solve(int N, int M, const StrVec &v)
{
int total = 0;
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= M; ++j) {
if (v[i][j] == '.') {
++total;
}
}
}
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= M; ++j) {
if (v[i][j] == '.') {
for (int d = 0; d < 4; ++d) {
if (check(N, M, v, total, j, i, d)) {
return true;
}
}
}
}
}
return false;
}
int main(int argc, char *argv[])
{
int N, M;
string s;
{
getline(cin, s);
stringstream ss(s);
ss >> N >> M;
}
StrVec v(N+2);
v[0] = string(102, '#');
for (int i = 0; i < N; ++i) {
getline(cin, s);
v[i + 1] = "#" + s + "#";
}
v[N+1] = string(102, '#');
cout << (solve(N, M, v) ? "YES" : "NO") << endl;
return 0;
}
hotpepsi