結果
| 問題 |
No.2412 YOU Grow Bigger!
|
| コンテスト | |
| ユーザー |
rniya
|
| 提出日時 | 2023-08-17 01:40:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,969 bytes |
| コンパイル時間 | 1,983 ms |
| コンパイル使用メモリ | 206,552 KB |
| 最終ジャッジ日時 | 2025-02-16 08:52:45 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 WA * 8 |
ソースコード
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
template <class T> istream& operator>>(istream& is, vector<T>& v) {
for (auto& x : v) is >> x;
return is;
}
template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
auto sep = "";
for (const auto& x : v) os << exchange(sep, " ") << x;
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }
template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }
template <class T> void mkuni(vector<T>& v) {
sort(begin(v), end(v));
v.erase(unique(begin(v), end(v)), end(v));
}
template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
vector<string> S(H);
for (auto& s : S) cin >> s;
vector ok(H, vector<bool>(W, false)), dp(H, vector<bool>(W, false));
auto check = [&]() {
for (int x = 1; x < H - 1; x++) {
for (int y = 1; y < W - 1; y++) {
ok[x][y] = true;
dp[x][y] = false;
}
}
for (int x = 0; x < H; x++) {
for (int y = 0; y < W; y++) {
if (S[x][y] != '#') continue;
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int nx = x + dx, ny = y + dy;
if (nx < 0 or H <= nx or ny < 0 or W <= ny) continue;
ok[nx][ny] = false;
}
}
}
}
queue<pair<int, int>> que;
dp[1][1] = true;
que.emplace(1, 1);
while (not que.empty()) {
auto [x, y] = que.front();
que.pop();
for (int dx = -1; dx <= 1; dx++) {
for (int dy = -1; dy <= 1; dy++) {
int nx = x + dx, ny = y + dy;
if (nx < 0 or H <= nx or ny < 0 or W <= ny) continue;
if (not ok[nx][ny]) continue;
if (dp[nx][ny]) continue;
dp[nx][ny] = true;
que.emplace(nx, ny);
}
}
}
return dp[H - 2][W - 2];
};
if (not check()) {
cout << 0 << '\n';
return 0;
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (S[i][j] == '#') continue;
S[i][j] = '#';
if (not check()) {
cout << 1 << '\n';
return 0;
}
S[i][j] = '.';
}
}
cout << 2 << '\n';
return 0;
}
rniya