結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2016-02-19 22:13:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 381 ms / 5,000 ms |
| コード長 | 1,869 bytes |
| コンパイル時間 | 606 ms |
| コンパイル使用メモリ | 72,360 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:48:35 |
| 合計ジャッジ時間 | 1,951 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <queue>
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
#include <tuple>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define ALL(container) (container).begin(), (container).end()
int f[200][200];
int visit[200][200];
int main(int argc, char *argv[]){
ios::sync_with_stdio(false);
int w,h;
cin >> w >> h;
REP(i, 200) REP(j, 200) f[i][j] = 0;
REP(i, 200) REP(j, 200) visit[i][j] = 0;
REP(i, h) REP(j, w)
{
int v;
cin >> v;
f[i+1][j+1] = v;
}
pii shifts[] = {{1,0},{0,1},{-1,0},{0,-1}};
REP(i, h) REP(j, w)
{
int sh = i + 1;
int sw = j + 1;
REP(k, 200) REP(l, 200) visit[k][l] = 0;
queue<tiii> q;
q.push(make_tuple(sw,sh,-1));
visit[sh][sw] = 1;
int num = f[sh][sw];
while(!q.empty())
{
const auto t = q.front();
q.pop();
int current = visit[get<1>(t)][get<0>(t)];
for(int s = 0;s < 4;s++)
{
if(s == get<2>(t))
{
continue;
}
auto x = get<0>(t) + shifts[s].first;
auto y = get<1>(t) + shifts[s].second;
if(f[y][x] != num)
{
continue;
}
if(visit[y][x])
{
cout << "possible" << endl;
return 0;
}
else
{
visit[y][x] = current + 1;
q.push(make_tuple(x,y,(s + 2) % 4));
}
}
}
}
cout << "impossible" << endl;
return 0;
}
nanophoto12