結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-06-19 15:24:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,406 bytes |
| コンパイル時間 | 622 ms |
| コンパイル使用メモリ | 72,012 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 05:21:27 |
| 合計ジャッジ時間 | 1,335 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 3 |
ソースコード
#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]) {
int x = m[i][j];
queue<pair<int,int>> q;
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 || ny >= w || x != 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