結果

問題 No.13 囲みたい!
ユーザー shisyamokongarishisyamokongari
提出日時 2016-09-22 18:49:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 321 ms / 5,000 ms
コード長 1,404 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 62,908 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 01:19:14
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 321 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 102 ms
4,376 KB
testcase_08 AC 95 ms
4,380 KB
testcase_09 AC 24 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 58 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:9: warning: ‘gh’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(th==gh&&tw==gw){
         ^~
main.cpp:61:18: warning: ‘gw’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(th==gh&&tw==gw){
            ~~~~~~^~~~~~~~

ソースコード

diff #

#include<iostream>
#include<stack>
using namespace std;

#define WMAX 100
#define HMAX 100
#define MMAX 1000

int main(){

	int W,H;
	int M[WMAX][HMAX];
	bool map[WMAX][HMAX];
	stack<int> vw,vh;

	cin>>W>>H;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>M[i][j];
		}
	}

	for(int i=1;i<=MMAX;i++){
		for(int j=0;j<H;j++){
			for(int k=0;k<W;k++){
				if(M[j][k]==i){
					for(int l=0;l<H;l++){
						for(int m=0;m<W;m++){
							map[l][m]=false;
						}
					}
					int dw[]={0,0,1,-1};
					int dh[]={1,-1,0,0};
					int c=0;
					int sw,sh;
					int gw,gh;
					for(int l=0;l<4;l++){
						int tw=k+dw[l];
						int th=j+dh[l];
						if(tw>=0&&tw<W&&th>=0&&th<H&&M[th][tw]==i){
							c++;
							if(c==1) sw=tw,sh=th;
							else gw=tw,gh=th;
						}
					}
					if(c<2) continue;
					map[j][k]=true;
					vw.push(sw);
					vh.push(sh);
					while(!vw.empty()){
						int nw=vw.top();
						int nh=vh.top();
						//cout<<i<<","<<nh<<","<<nw<<endl;
						vw.pop();
						vh.pop();
						for(int l=0;l<4;l++){
							int tw=nw+dw[l];
							int th=nh+dh[l];
							//cout<<th<<","<<tw<<endl;
							if(tw>=0&&tw<W&&th>=0&&th<H&&M[th][tw]==i&&map[th][tw]==false){
								if(th==gh&&tw==gw){
									cout<<"possible"<<endl;
									return 0;
								}
								map[th][tw]=true;
								vw.push(tw);
								vh.push(th);
							}
						}
					}
				}
			}
		}
	}
	cout<<"impossible"<<endl;
}
0