結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2015-06-02 00:01:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,666 bytes |
| コンパイル時間 | 784 ms |
| コンパイル使用メモリ | 90,108 KB |
| 実行使用メモリ | 814,128 KB |
| 最終ジャッジ日時 | 2024-07-06 13:17:43 |
| 合計ジャッジ時間 | 4,592 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 MLE * 1 -- * 12 |
ソースコード
#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];
bool check(int s){
int N = W*H;
vector<int> visited(N, 0);
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,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);
G[ny*W+nx].push_back(i*W+j);
}
}
}
}
}
rep(i,1005){
if(xx[i] >= 0){
if(check(xx[i])){
cout << "possible" << endl;
return 0;
}
}
}
cout << "impossible" << endl;
return 0;
}
どらら