結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-04-24 00:30:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,057 bytes |
| コンパイル時間 | 598 ms |
| コンパイル使用メモリ | 51,712 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-13 10:43:20 |
| 合計ジャッジ時間 | 1,019 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:7:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <queue>
#include <cstdio>
#include <functional>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
int main(){
const int w = getInt();
const int h = getInt();
vector<vector<int> > g(h, vector<int>(w));
REP(i,h) REP(j,w) g[i][j] = getInt();
vector<vector<int> > f(h, vector<int>(w));
function<bool(int, int, int, int)> dfs = [&](int y, int x, int py, int px){
if(f[y][x]) return true;
f[y][x] = true;
REP(i,4){
const int xx = x + _dx[i];
const int yy = y + _dy[i];
if(ISIN(xx, yy, w, h) && (xx != px || yy != py) && g[y][x] == g[yy][xx])
if(dfs(yy, xx, y, x)) return true;
}
return false;
};
bool ans = false;
REP(i,h) REP(j,w) if(!f[i][j])
ans |= dfs(i, j, -1, -1);
puts(ans ? "possible" : "impossible");
return 0;
}
y_mazun