結果

問題 No.13 囲みたい!
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-01 12:45:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,158 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 68,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 14:09:05
合計ジャッジ時間 7,814 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 OLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <queue>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int w, h;
int b[110][110];
int used[110][110];
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
int main(void){
	cin >> w >> h;
	rep(i, h)rep(j, w) cin >> b[i][j];
	rep(i, h)rep(j, w) used[i][j] = 0;

	rep(i, h)rep(j, w){
		printf("%d %d\n", i, j);
		rep(a, h)rep(b, w)used[a][b] = 0;
		queue<pair<int, int> > q;
		int num = b[i][j];
		used[i][j] = 1;//逆戻りを防ぐように
		q.push(make_pair(i, j));
		while(!q.empty()){
			auto now = q.front(); q.pop();
			rep(k, 4){
				int y = now.first + dy[k], x = now.second + dx[k];
				if(y < 0 && h <= y && x < 0 && w <= x) continue;
				if(y == i && x == j && used[now.first][now.second] >= 3){
					printf("possible\n");
					return 0;
				}
				if(b[y][x] == num && used[y][x] == 0){
					q.push(make_pair(y, x));
					used[y][x] = used[now.first][now.second] + 1;
					break;
				}

			}
		}
		
		rep(a, h){
			rep(b, w){
				printf("%d ", used[a][b]);
			}
			printf("\n");
		}
		
	}
	printf("impossible\n");
	return 0;
}
0