結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 21:25:12 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,074 bytes |
| 記録 | |
| コンパイル時間 | 2,623 ms |
| コンパイル使用メモリ | 230,000 KB |
| 実行使用メモリ | 136,320 KB |
| 最終ジャッジ日時 | 2026-04-17 21:26:11 |
| 合計ジャッジ時間 | 58,576 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 79 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
int main() {
ll H, W;
cin >> H >> W;
vector<string> S(H);
for (ll i = 0; i < H; i++) cin >> S[i];
S[0][0] = '.';
S[H - 1][W - 1] = '.';
queue<tuple<ll, ll, ll, ll>> que;
que.emplace(0, 0, 0, 0);
vector<vector<vector<ll>>> memo(3,
vector<vector<ll>>(H, vector<ll>(W, -1)));
// 0: 普通
// 1: 上下
// 2: 左右
while (!que.empty()) {
ll dis, t, x, y;
tie(dis, t, x, y) = que.front();
que.pop();
if (t == 0 && S[x][y] == '#') continue;
if (memo[t][x][y] == -1) {
//cerr <<dis << " "<< t << " " << x << " " << y << endl;
memo[t][x][y] = dis;
if (t == 0) {
if (x != 0) {
que.emplace(dis + 1, 0, x - 1, y);
que.emplace(dis + 1, 2, x - 1, y);
}
if (x != H - 1) {
que.emplace(dis + 1, 0, x + 1, y);
que.emplace(dis + 1, 2, x, y);
}
if (y != 0) {
que.emplace(dis + 1, 0, x, y - 1);
que.emplace(dis + 1, 1, x, y - 1);
}
if (y != W - 1) {
que.emplace(dis + 1, 0, x, y + 1);
que.emplace(dis + 1, 1, x, y);
}
}
if (t == 1) {
if (x != 0) { que.emplace(dis + 1, 1, x - 1, y); }
if (x != H - 1) { que.emplace(dis + 1, 1, x + 1, y); }
que.emplace(dis + 1, 0, x, y);
que.emplace(dis + 1, 0, x, y + 1);
}
if(t == 2){
if (y != 0) { que.emplace(dis + 1, 2, x, y - 1); }
if (y != W - 1) { que.emplace(dis + 1, 2, x, y + 1); }
que.emplace(dis + 1, 0, x, y);
que.emplace(dis + 1, 0, x + 1, y);
}
}
}
cout << memo[0][H - 1][W - 1] << endl;
}