結果

問題 No.13 囲みたい!
ユーザー togari_takamototogari_takamoto
提出日時 2015-12-14 02:04:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,218 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-13 16:03:50
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <iomanip>
#include <numeric>
#include <memory>
#include <set>
#include <cassert>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TEN(x) ((ll)1e##x)
#define ALL(v) (v).begin(), (v).end()
//          0  1  2  3
ll dx[] = { 1, 0, 0, -1 };
ll dy[] = { 0, 1, -1, 0 };

ll m[100][100]; // m[h][w];
ll w, h;
bool visited[100][100];

bool is_inner(ll x, ll y) { return !(x < 0 || w <= x || y < 0 || h <= y); }

bool bfs(ll x, ll y, ll d) {
	if (visited[y][x]) return true;
	visited[y][x] = true;
	REP(i, 4) if (i != d) if (is_inner(x + dx[i], y + dy[i])) if (m[y][x] == m[y + dy[i]][x + dx[i]]) {
		if (bfs(x + dx[i], y + dy[i], 3 - i)) return true;
	}
	return false;
}

int main(){
	cin >> w >> h;
	REP(y, h) REP(x, w) cin >> m[y][x];
	fill(visited[0], visited[0] + 101 * 101, false);
	REP(y, h) REP(x, w) if (!visited[y][x]) if (bfs(x, y, -1)) {
		cout << "possible" << endl;
		return 0;
	}
	cout << "impossible" << endl;
	return 0;
}
0