結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2015-06-02 00:28:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,670 bytes |
| コンパイル時間 | 731 ms |
| コンパイル使用メモリ | 88,324 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:44:09 |
| 合計ジャッジ時間 | 1,489 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
int W, H;
int field[105][105];
vector<int> G[10005];
int vx[4] = {0,0,1,-1};
int vy[4] = {1,-1,0,0};
int xx[1005];
int visited[10005];
bool check(int s){
queue< pair<int,int> > que;
que.push(make_pair(s, -1));
while(!que.empty()){
pair<int,int> p = que.front(); que.pop();
visited[p.first] = 1;
rep(i,G[p.first].size()){
if(G[p.first][i] == p.second) continue;
if(visited[G[p.first][i]] == 1) return true;
que.push(make_pair(G[p.first][i], p.first));
}
}
return false;
}
int main(){
cin >> W >> H;
rep(i,H){
rep(j,W){
cin >> field[i][j];
}
}
rep(i,1005){
xx[i] = -1;
}
rep(i,10005) visited[i] = 0;
rep(i,H){
rep(j,W){
xx[field[i][j]] = i*W+j;
rep(k,4){
int nx = j+vx[k], ny = i+vy[k];
if(0<=nx && nx<W && 0<=ny && ny<H){
if(field[i][j] == field[ny][nx]){
G[i*W+j].push_back(ny*W+nx);
}
}
}
}
}
rep(i,H){
rep(j,W){
if(visited[i*W+j] == 0){
if(check(i*W+j)){
cout << "possible" << endl;
return 0;
}
}
}
}
cout << "impossible" << endl;
return 0;
}
どらら