結果

問題 No.13 囲みたい!
ユーザー tkmst201tkmst201
提出日時 2017-05-16 20:51:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,367 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 159,788 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 12:30:57
合計ジャッジ時間 2,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 12 ms
4,348 KB
testcase_04 AC 12 ms
4,348 KB
testcase_05 AC 12 ms
4,348 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 12 ms
4,348 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 12 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 10 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |         REP(i, h) REP(j, w) scanf("%d", &maps[i][j]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int w, h;
int maps[100][100];
bool done[100][100];

bool dfs(int num, int x, int y, int prev) {
	if (done[y][x]) return true;
	done[y][x] = true;
	
	static int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
	
	REP(i, 4) {
		int nx = x + dx[i], ny = y + dy[i];
		
		if (!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue;
		if (maps[ny][nx] != num) continue;
		if (ny * w + nx == prev) continue;
		
		if (dfs(num, nx, ny, y * w + x)) return true;
	}
	
	return false;
}


int main() {
	cin >> w >> h;
	REP(i, h) REP(j, w) scanf("%d", &maps[i][j]);
	
	bool ans = false;
	
	FOR(i, 1, 1000) {
		memset(done, 0, sizeof(done));
		REP(y, h) REP(x, w) {
			if (maps[y][x] == i && !done[y][x]) {
				if (dfs(i, x, y, -1)) ans = true;
			}
		}
	}
	
	puts(ans ? "possible" : "impossible");
	
	return 0;
}
0