結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
hotpepsi
|
| 提出日時 | 2015-03-16 23:21:47 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,152 bytes |
| コンパイル時間 | 1,038 ms |
| コンパイル使用メモリ | 65,732 KB |
| 実行使用メモリ | 814,080 KB |
| 最終ジャッジ日時 | 2024-06-28 23:06:46 |
| 合計ジャッジ時間 | 3,041 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 MLE * 1 -- * 11 |
ソースコード
#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>
using namespace std;
int W, H;
int d[100][100];
int vis[100][100];
int sx, sy;
bool dfs(int x, int y, int prevx, int prevy) {
vis[y][x] = 1;
if (x == sx && y == sy) {
return true;
}
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
for (int dir = 0; dir < 4; ++dir) {
int nx = x + dx[dir], ny = y + dy[dir];
if (nx >= 0 && nx < W && ny >= 0 && ny < H && (nx != prevx || ny != prevy) && d[y][x] == d[ny][nx]) {
if (dfs(nx, ny, x, y)) {
return true;
}
}
}
return false;
}
int main(int argc, char *argv[]) {
string s;
getline(cin, s);
stringstream ss(s);
ss >> W >> H;
for (int i = 0; i < H; ++i) {
getline(cin, s);
stringstream ss(s);
for (int j = 0; j < W; ++j) {
ss >> d[i][j];
}
}
bool possible = false;
for (int i = 0; i < H; ++i) {
for (int j = 1; j < W; ++j) {
if (d[i][j - 1] == d[i][j]) {
memset(vis, 0, sizeof(vis));
sx = j - 1, sy = i;
if (dfs(j, i, j - 1, i)) {
possible = true;
}
}
}
}
cout << (possible ? "possible" : "impossible") << endl;
return 0;
}
hotpepsi