結果

問題 No.13 囲みたい!
ユーザー spade630spade630
提出日時 2015-10-18 23:30:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,492 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 72,392 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:21:51
合計ジャッジ時間 1,412 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5 + 1;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int W, H;
int maze[128][128];
bool visited[128][128];

bool check(int x, int y){
	return x >= 0 && x < W && y >= 0 && y < H; 	
}

bool dfs(int x, int y, int prev){
	visited[y][x] = true;
	REP(i,4){
		if(i == prev)
			continue;
		
		int nx = x + dx[i], ny = y + dy[i];
		if(!check(nx, ny))
			continue;
		if(maze[y][x] != maze[ny][nx])
			continue;
		if(visited[ny][nx])
			return true;
		if(dfs(nx, ny, (i + 2) % 4))
			return true;
	}
	return false;
}

int main() {
	cin >> W >> H;
	REP(i,H)REP(j,W)
		scanf("%d", &maze[i][j]);
	REP(i,H)REP(j,W){
		if(!visited[i][j]){
			if(dfs(j, i, -1)){
				cout << "possible" << endl;
				exit(0);
			}
		}
	}
	cout << "impossible" << endl;
	return 0;
}
0