結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
AK_Mi
|
| 提出日時 | 2026-04-18 14:59:19 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 2,000 ms |
| コード長 | 1,965 bytes |
| 記録 | |
| コンパイル時間 | 3,625 ms |
| コンパイル使用メモリ | 348,504 KB |
| 実行使用メモリ | 8,704 KB |
| 最終ジャッジ日時 | 2026-04-18 14:59:45 |
| 合計ジャッジ時間 | 9,717 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 85 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
//using mint = modint998244353;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll h,w;
cin >> h >> w;
vector<string> mass(h);
for(ll i = 0; i < h; i++){
cin >> mass[i];
}
ll ans = h+w;
vector<ll> dx = {1,0,-1,0};
vector<ll> dy = {0,1,0,-1};
vector<vector<bool>> come(h,vector<bool>(w,0));
queue<ll> que;
ll maxx = 0;
ll maxy = 0;
que.push(0);
come[0][0] = 1;
while(!que.empty()){
ll x = que.front() / 10000;
ll y = que.front() % 10000;
que.pop();
for(ll i = 0; i < 2; i++){
ll xx = x + dx[i];
ll yy = y + dy[i];
if(xx >= h)continue;
if(yy >= w)continue;
if(come[xx][yy])continue;
if(mass[xx][yy] == '#')continue;
come[xx][yy] = 1;
maxx = max(maxx,xx);
maxy = max(maxy,yy);
que.push(xx * 10000 + yy);
}
}
if(come[h-1][w-1])ans -= 2;
else{
ll minx = h-1;
ll miny = w-1;
que.push((h-1)*10000 + w-1);
come[h-1][w-1] = 1;
while(!que.empty()){
ll x = que.front() / 10000;
ll y = que.front() % 10000;
que.pop();
for(ll i = 2; i < 4; i++){
ll xx = x + dx[i];
ll yy = y + dy[i];
if(xx < 0)continue;
if(yy < 0)continue;
if(come[xx][yy])continue;
if(mass[xx][yy] == '#')continue;
come[xx][yy] = 1;
minx = min(minx,xx);
miny = min(miny,yy);
que.push(xx * 10000 + yy);
}
}
if(minx - maxx < 2 || miny - maxy < 2)ans--;
}
cout << ans << '\n';
}
AK_Mi