結果
| 問題 |
No.2412 YOU Grow Bigger!
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-08-11 22:09:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,724 bytes |
| コンパイル時間 | 3,896 ms |
| コンパイル使用メモリ | 260,372 KB |
| 最終ジャッジ日時 | 2025-02-16 01:29:21 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 WA * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
bool solve(int h, int w, vector<vector<char>> &c){
vector<vector<bool>> tansaku(h-2, vector<bool>(w-2));
tansaku[0][0] = true;
rep(i,0,3){
rep(j,0,3){
if (c[i][j] == '#') return false;
}
}
vector<vector<bool>> good(h-2, vector<bool>(w-2));
rep(x,0,h-2){
rep(y,0,w-2){
bool mode = true;
rep(xx,x,x+3){
rep(yy,y,y+3){
if (c[xx][yy] == '#'){
mode = false;
}
}
}
good[x][y] = mode;
}
}
vector<pair<int,int>> mada = {pair(0, 0)};
while(!mada.empty()){
auto [i, j] = mada.back();
mada.pop_back();
rep(x,i-1,i+2){
rep(y,j-1,j+2){
if (!(0 <= x && x < h-2)) continue;
if (!(0 <= y && y < w-2)) continue;
if (tansaku[x][y]) continue;
if (!good[x][y]) continue;
tansaku[x][y] = true;
mada.push_back(pair(x, y));
}
}
}
return tansaku[h-3][w-3];
}
int main(){
int h, w; cin >> h >> w;
vector<vector<char>> c(h, vector<char>(w));
rep(i,0,h){
rep(j,0,w){
cin >> c[i][j];
}
}
if (!solve(h, w, c)){
cout << 0 << '\n';
return 0;
}
rep(i,w-4,w){
vector<vector<char>> cc = c;
cc[h-4][i] = '#';
if (!solve(h, w, cc)){
cout << 1 << '\n';
return 0;
}
}
rep(i,h-4,h){
vector<vector<char>> cc = c;
cc[i][w-4] = '#';
if (!solve(h, w, cc)){
cout << 1 << '\n';
return 0;
}
}
vector<pair<int,int>> tans = {pair(h-4, w-4), pair(h-3, w-4), pair(h-2, w-4), pair(h-1, w-4), pair(h-4, w-3), pair(h-4, w-2), pair(h-4, w-1)};
int m = tans.size();
rep(i,0,m){
rep(j,i+1,m){
vector<vector<char>> cc = c;
cc[tans[i].first][tans[i].second] = '#';
cc[tans[j].first][tans[j].second] = '#';
if (!solve(h, w, cc)){
cout << 2 << '\n';
return 0;
}
}
}
}
shobonvip