結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 21:56:26 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,012 bytes |
| 記録 | |
| コンパイル時間 | 2,218 ms |
| コンパイル使用メモリ | 228,328 KB |
| 実行使用メモリ | 226,560 KB |
| 最終ジャッジ日時 | 2026-04-17 21:57:06 |
| 合計ジャッジ時間 | 33,450 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 WA * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H,W; cin >> H >> W;
vector<string> S(H);
for(auto &s : S) cin >> s;
const int inf = 1001001001;
vector<vector<vector<int>>> dist(H,vector(W,vector<int>(3,inf)));
dist.at(0).at(0).at(0) = 0;
vector<pair<int,int>> dxy = {{-1,0},{0,1},{1,0},{0,-1}};
queue<tuple<int,int,int>> Q; Q.push({0,0,0});
auto check = [&](int x,int y,int d,int v) -> void {
if(dist.at(x).at(y).at(d) == inf) dist.at(x).at(y).at(d) = v,Q.push({x,y,d});
};
while(Q.size()){
auto [x,y,d] = Q.front(); Q.pop();
int now = dist.at(x).at(y).at(d)+1;
check(x,y,1,now),check(x,y,2,now);
if(x < H-1 && (S.at(x+1).at(y) != '#' || d == 1)) check(x+1,y,d,now);
if(y < W-1 && (S.at(x).at(y+1) != '#' || d == 2)) check(x,y+1,d,now);
}
cout << *min_element(dist.at(H-1).at(W-1).begin(),dist.at(H-1).at(W-1).end()) << endl;
}