結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-23 05:30:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 852 bytes |
| コンパイル時間 | 2,254 ms |
| コンパイル使用メモリ | 162,284 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:43:19 |
| 合計ジャッジ時間 | 2,651 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))
int W, H;
int a[110][110];
vector<int> g[10000];
bool vis[10000];
bool cycle = false;
void dfs(int p, int prev) {
if (vis[p]) {
cycle = true;
return;
}
vis[p] = true;
REP(i, g[p].size()) if (prev != g[p][i]) {
dfs(g[p][i], p);
}
}
int main() {
cin >> W >> H;
REP(i, H) REP(j, W) cin >> a[i][j];
int di[] = {0, 1, 0, -1};
int dj[] = { 1, 0, -1, 0 };
REP(i, H) REP(j, W) {
REP(k, 4) {
int ni = i + di[k];
int nj = j + dj[k];
if (0 <= ni && ni < H && 0 <= nj && nj < W && a[i][j] == a[ni][nj]) {
int p1 = i * W + j;
int p2 = ni * W + nj;
g[p1].push_back(p2);
}
}
}
cycle = false;
REP(p, H * W) if (!vis[p]) {
dfs(p, -1);
}
cout << (cycle ? "possible " : "impossible ") << endl;
}