結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2015-05-03 21:13:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,581 bytes |
| コンパイル時間 | 853 ms |
| コンパイル使用メモリ | 97,180 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-05 17:45:08 |
| 合計ジャッジ時間 | 1,499 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 15 |
ソースコード
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;
int H, W;
int M[110][110];
vector<list<P>> cd;
#define mp(a,b,c,d) make_pair( make_pair((a),(b)),make_pair((c),(d)) )
#define dir(xx,yy,x,y,i)(xx)=(x)+dir[(i)],(yy)=(y)+dir[(i)+1];
const int dir[] = { 0, 1, 0, -1, 0 };
bool bfs(int c){
cout << c << endl;
queue<PP> que;
for (auto &u : cd[c])
if(M[u.first][u.second]==c){
que.push(mp(u.first, u.second, -1, -1));
M[u.first][u.second] *= -1;
while (que.empty() == false){
auto v = que.front(); que.pop();
for (int i = 0; i < 4; i++){
int xx, yy;
dir(xx, yy, v.first.first, v.first.second, i);
if ((xx != v.second.first) || (yy != v.second.second)){
if (M[xx][yy] == -c){
return true;
}
if (M[xx][yy] == c){
M[xx][yy] *= -1;
que.push(mp(xx, yy, v.first.first, v.first.second));
}
}
}
}
}
return false;
}
int main(void){
cd.resize(1010);
cin >> W >> H;
for (int i = 1; i <=H; i++)
{
for (int j = 1; j <= W; j++)
{
cin >> M[i][j];
cd[M[i][j]].push_back(make_pair(i, j));
}
}
for (int i = 1; i <= 1000; i++)
if (cd[i].size() >= 4)
if (bfs(i))
{
cout << "possible" << endl;
return 0;
}
cout << "impossible" << endl;
return 0;
}
btk