結果
| 問題 |
No.13 囲みたい!
|
| コンテスト | |
| ユーザー |
assy1028
|
| 提出日時 | 2015-03-21 16:09:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,721 bytes |
| コンパイル時間 | 1,221 ms |
| コンパイル使用メモリ | 84,708 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 10:42:13 |
| 合計ジャッジ時間 | 1,962 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:70:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
70 | scanf("%d%d", &w, &h);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:76:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
76 | scanf("%d", &m[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1000000009;
int m[102][102];
bool used[102][102];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool dfs(int x, int y, int prevx, int prevy) {
used[x][y] = true;
for (int i = 0; i < 4; i++) {
int X = x + dx[i], Y = y + dy[i];
if (!(X == prevx && Y == prevy) && m[X][Y] == m[x][y]) {
if (used[X][Y])
return true;
if (dfs(X, Y, x, y))
return true;
}
}
return false;
}
bool solve(int h, int w) {
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (!used[i][j]) {
if (dfs(i, j, -1, -1))
return true;
}
}
}
return false;
}
int main() {
int w, h;
scanf("%d%d", &w, &h);
memset(m, 0, sizeof(m));
memset(used, false, sizeof(used));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
scanf("%d", &m[i][j]);
}
}
printf("%s\n", solve(h, w) ? "possible" : "impossible");
}
assy1028