結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
tkmst201
|
| 提出日時 | 2017-05-16 20:51:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 5,000 ms |
| コード長 | 1,367 bytes |
| コンパイル時間 | 1,081 ms |
| コンパイル使用メモリ | 158,472 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-17 10:37:59 |
| 合計ジャッジ時間 | 1,771 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | REP(i, h) REP(j, w) scanf("%d", &maps[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
int w, h;
int maps[100][100];
bool done[100][100];
bool dfs(int num, int x, int y, int prev) {
if (done[y][x]) return true;
done[y][x] = true;
static int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
REP(i, 4) {
int nx = x + dx[i], ny = y + dy[i];
if (!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue;
if (maps[ny][nx] != num) continue;
if (ny * w + nx == prev) continue;
if (dfs(num, nx, ny, y * w + x)) return true;
}
return false;
}
int main() {
cin >> w >> h;
REP(i, h) REP(j, w) scanf("%d", &maps[i][j]);
bool ans = false;
FOR(i, 1, 1000) {
memset(done, 0, sizeof(done));
REP(y, h) REP(x, w) {
if (maps[y][x] == i && !done[y][x]) {
if (dfs(i, x, y, -1)) ans = true;
}
}
}
puts(ans ? "possible" : "impossible");
return 0;
}
tkmst201