結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
atn112323
|
| 提出日時 | 2016-05-04 21:39:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,040 bytes |
| コンパイル時間 | 572 ms |
| コンパイル使用メモリ | 65,692 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 10:53:22 |
| 合計ジャッジ時間 | 1,119 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
const int DX[] = {1, 0, -1, 0};
const int DY[] = {0, 1, 0, -1};
int W, H;
int M[100][100];
bool visited[100][100];
int main() {
cin >> W >> H;
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
cin >> M[x][y];
}
}
for (int x = 0; x < W; x++) {
for (int y = 0; y < H; y++) {
if (!visited[x][y]) {
queue<pair<int, int> > Q;
Q.push(make_pair(x + y * W, -1));
while (!Q.empty()) {
pair<int, int> p = Q.front();
Q.pop();
int cx = p.first % W, cy = p.first / W;
if (visited[cx][cy]) {
cout << "possible" << endl;
return 0;
}
visited[cx][cy] = true;
for (int d = 0; d < 4; d++) {
if (p.second == (d + 2) % 4) {
continue;
}
int xx = cx + DX[d], yy = cy + DY[d];
if (0 <= xx && xx < W && 0 <= yy && yy < H && M[xx][yy] == M[cx][cy]) {
Q.push(make_pair(xx + yy * W, d));
}
}
}
}
}
}
cout << "impossible" << endl;
return 0;
}
atn112323