結果
| 問題 |
No.13 囲みたい!
|
| ユーザー |
A63635985
|
| 提出日時 | 2018-03-01 22:54:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,728 bytes |
| コンパイル時間 | 725 ms |
| コンパイル使用メモリ | 73,232 KB |
| 実行使用メモリ | 814,336 KB |
| 最終ジャッジ日時 | 2024-12-26 01:01:36 |
| 合計ジャッジ時間 | 22,225 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 TLE * 2 MLE * 3 |
ソースコード
#include <iostream>
#include <queue>
#include <map>
#include <vector>
using namespace std;
struct Struct{
int h,w,count;
bool operator<(const Struct &other)const{
if(h==other.h)
return w<other.w;
else
return h<other.h;
}
};
int H,W;
int direction[5]={-1,0,1,0,-1};
int field[101][101];
Struct start;
bool recursion(Struct now,int color,map<Struct,bool>past){
if(now.h<0 || now.h>=H)return false;
if(now.w<0 || now.w>=W)return false;
if(field[now.h][now.w]!=color)return false;
if(now.h==start.h && now.w==start.w && now.count>3)return true;
if(past[now])return false;
past[now]=true;
bool response=false;
for(int i=0 ; i<4 ; i++ ){
Struct next;
next.h=now.h+direction[i];
next.w=now.w+direction[i+1];
next.count=now.count+1;
response|=recursion(next,color,past);
}
return response;
}
int main(){
cin >> W >> H;
for(int i=0 ; i<H ; i++ )
for(int j=0 ; j<W ; j++ )
cin >> field[i][j];
for(int i=0 ; i<H ; i++ ){
for(int j=0 ; j<W ; j++ ){
map<Struct,bool> past;
start.h=i;start.w=j;
Struct now;
now.h=i;now.w=j;now.count=0;
if(recursion(now,field[i][j],past)){
cout<<"possible"<<endl;
return 0;
}
}
}
cout<<"impossible"<<endl;
return 0;
}
A63635985