結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
shisyamokongari
|
| 提出日時 | 2016-09-22 18:49:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 5,000 ms |
| コード長 | 1,404 bytes |
| コンパイル時間 | 581 ms |
| コンパイル使用メモリ | 62,580 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 13:10:55 |
| 合計ジャッジ時間 | 1,675 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
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){
| ~~~~~~^~~~~~~~
ソースコード
#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;
}
shisyamokongari