結果
問題 |
No.13 囲みたい!
|
ユーザー |
|
提出日時 | 2014-10-31 12:58:04 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,145 bytes |
コンパイル時間 | 1,239 ms |
コンパイル使用メモリ | 61,588 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-12-30 15:19:31 |
合計ジャッジ時間 | 13,059 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 TLE * 2 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int W, H; int M[111][111]; bool used[111][111]; bool dfs(int y, int x, int py, int px){ if(y < 0 || y >= H || x < 0 || x >= W)return false; if(M[y][x] != M[py][px])return false; if(used[y][x])return true; used[y][x] = true; vector<int> rnd(4); for(int i=0;i<4;i++)rnd[i] = i; random_shuffle(rnd.begin(), rnd.end()); bool res = false; for(int i=0;i<4;i++){ int k = rnd[i]; int ny = y + dy[k]; int nx = x + dx[k]; if(ny == py && nx == px)continue; res |= dfs(ny, nx, y, x); } used[y][x] = false; return res; } int main(){ cin >> W >> H; for(int y=0;y<H;y++)for(int x=0;x<W;x++)cin >> M[y][x]; for(int y=0;y<H;y++)for(int x=0;x<W;x++){ bool res = dfs(y, x, y, x); if(res){ cout << "possible" << endl; return 0; } } cout << "impossible" << endl; return 0; }