結果

問題 No.13 囲みたい!
ユーザー shisyamokongarishisyamokongari
提出日時 2016-09-22 18:49:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 210 ms / 5,000 ms
コード長 1,404 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 64,128 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 18:28:42
合計ジャッジ時間 1,509 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 210 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 27 ms
6,940 KB
testcase_08 AC 21 ms
6,940 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 16 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 8 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:65: warning: ‘gh’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |                                                                 if(th==gh&&tw==gw){
      |                                                                 ^~
main.cpp:61:74: warning: ‘gw’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |                                                                 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