結果

問題 No.13 囲みたい!
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-10 20:40:24
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 701 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 159,168 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 12:22:18
合計ジャッジ時間 3,508 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int dfs(int, int, int, int)’:
main.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
   21 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int done[110][110];
int a[110][110];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int H,W;
int ok = 0;
int dfs(int x,int y,int px,int py){
	if( done[y][x] ) return 0;
	done[y][x] = 1;
	for(int i = 0 ; i < 4 ; i++){
		int tx = x + dx[i];
		int ty = y + dy[i];
		if( tx == px && ty == py ) continue;
		if( a[ty][tx] != a[y][x] ) continue;
		if( done[ty][tx] ) ok = 1;
		dfs(tx,ty,x,y);
	}
}


int main(){
	cin >> W >> H;
	for(int i = 1 ; i <= H ; i++){
		for(int j = 1 ; j <= W ; j++){
			cin >> a[i][j];
		}
	}
	
	for(int i = 1 ; i <= H ; i++){
		for(int j = 1 ; j <= W ; j++){
			dfs(j,i,-1,-1);
		}
	}
	cout << (ok?"possible":"impossible") << endl;
	
}
0