結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-06-19 15:35:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,414 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 72,268 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:53:56 |
| 合計ジャッジ時間 | 1,347 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
#define INF (int)1e8
#define MOD (int)(1e9+7)
typedef long long ll;
int m[100][100];
bool used[100][100];
int main(void) {
int i, j, w, h;
cin >> w >> h;
rep (i,h) rep (j,w) cin >> m[i][j];
bool ans = false;
rep (i,h) rep (j,w) if (!used[i][j]) {
queue<pair<int,int>> q;
used[i][j] = true;
q.push(make_pair(i,j));
while (!q.empty()) {
int y = q.front().first;
int x = q.front().second;
q.pop();
int dxy[] = {1,0,-1,0};
int k, cnt = 0;
rep (k,4) {
int ny = y + dxy[k];
int nx = x + dxy[(k+1)%4];
if (ny < 0 || ny >= h || nx < 0 || nx >= w || m[i][j] != m[ny][nx]) continue;
if (used[ny][nx]) {
cnt++;
continue;
}
used[ny][nx] = true;
q.push(make_pair(ny,nx));
}
if (cnt > 1)
ans = true;
}
}
if (ans)
cout << "possible" << endl;
else
cout << "impossible" << endl;
return 0;
}
h_noson