結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
togari_takamoto
|
| 提出日時 | 2015-12-14 02:06:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,212 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 88,504 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:48:00 |
| 合計ジャッジ時間 | 1,568 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <iomanip>
#include <numeric>
#include <memory>
#include <set>
#include <cassert>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(ll i=0; i<(n); ++i)
#define TEN(x) ((ll)1e##x)
#define ALL(v) (v).begin(), (v).end()
// 0 1 2 3
ll dx[] = { 1, 0, 0, -1 };
ll dy[] = { 0, 1, -1, 0 };
ll m[100][100]; // m[h][w];
ll w, h;
bool visited[100][100];
bool is_inner(ll x, ll y) { return !(x < 0 || w <= x || y < 0 || h <= y); }
bool bfs(ll x, ll y, ll d) {
if (visited[y][x]) return true;
visited[y][x] = true;
REP(i, 4) if (i != d) if (is_inner(x + dx[i], y + dy[i])) if (m[y][x] == m[y + dy[i]][x + dx[i]]) {
if (bfs(x + dx[i], y + dy[i], 3 - i)) return true;
}
return false;
}
int main(){
cin >> w >> h;
REP(y, h) REP(x, w) cin >> m[y][x];
REP(y, h) REP(x, w) visited[y][x] = false;
REP(y, h) REP(x, w) if (!visited[y][x]) if (bfs(x, y, -1)) {
cout << "possible" << endl;
return 0;
}
cout << "impossible" << endl;
return 0;
}
togari_takamoto