結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 06:06:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,086 bytes |
| コンパイル時間 | 671 ms |
| コンパイル使用メモリ | 54,264 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:39:10 |
| 合計ジャッジ時間 | 1,332 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d %d", &W, &H);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:33:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d", &M[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <cstdio>
int W, H;
int M[100][100];
bool used[100][100];
const int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
int dfs(int x, int y, int prev, int type){
used[y][x] = true;
bool f = false;
for(int i=0;i<4;i++){
if(i == 3-prev){continue;}
int nx = x + dx[i], ny = y + dy[i];
if(0 <= nx && nx < W &&
0 <= ny && ny < H && M[ny][nx] == type){
if(used[ny][nx]){return true;}
f = f || dfs(nx, ny, i, type);
}
}
return f;
}
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]);
}
}
std::fill(&used[0][0], &used[0][0]+100*100, false);
bool can = false;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(!used[i][j]){
can = can || dfs(j, i, -1, M[i][j]);
}
}
}
if(can){
puts("possible");
}else{
puts("impossible");
}
}
tottoripaper