結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2015-07-18 12:09:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,338 bytes |
| コンパイル時間 | 522 ms |
| コンパイル使用メモリ | 72,356 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:44:41 |
| 合計ジャッジ時間 | 1,104 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:52:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | scanf("%d%d",&w,&h);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:56:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%d",&m[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define MAX_L 5000000
#define SIZE 100001
int w,h;
int m[100][100];
int mo[5]={0,1,0,-1,0};
bool visit[100][100]={0};
bool dfs(int y,int x,int by,int bx){
if(y<0 || x<0 || h<=y || w<=x) return false;
if(visit[y][x]==true) return true;
visit[y][x]=true;
for(int i=0;i<4;i++){
if(y+mo[i]==by && x+mo[i+1]==bx) continue;
if(m[y][x]==m[y+mo[i]][x+mo[i+1]])
if(dfs(y+mo[i],x+mo[i+1],y,x)){
return true;
}
}
return false;
}
int main(){
scanf("%d%d",&w,&h);
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
scanf("%d",&m[i][j]);
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(visit[i][j]==false){
if(dfs(i,j,-1,-1)){
puts("possible");
return 0;
}
}
}
}
puts("impossible");
return 0;
}
goodbaton