結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 04:27:58 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,223 bytes |
| 記録 | |
| コンパイル時間 | 1,254 ms |
| コンパイル使用メモリ | 189,044 KB |
| 実行使用メモリ | 26,880 KB |
| 最終ジャッジ日時 | 2026-04-18 04:28:29 |
| 合計ジャッジ時間 | 28,082 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 63 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
const int INF = 1e9;
int main() {
int H, W;
cin >> H >> W;
vector<string> C(H);
for (int i = 0; i < H; ++i) cin >> C[i];
vector<vector<int>> dist(H, vector<int>(W, INF));
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
dist[0][0] = 0;
pq.push({0, {0, 0}});
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};
while (!pq.empty()) {
int d = pq.top().first;
int y = pq.top().second.first;
int x = pq.top().second.second;
pq.pop();
if (d > dist[y][x]) continue;
for (int i = 0; i < 4; ++i) {
int ny = y + dy[i];
int nx = x + dx[i];
if (ny >= 0 && ny < H && nx >= 0 && nx < W) {
int cost = 1;
if (C[ny][nx] == '#' && C[y][x] != '#') cost = 2;
if (dist[ny][nx] > d + cost) {
dist[ny][nx] = d + cost;
pq.push({dist[ny][nx], {ny, nx}});
}
}
}
}
cout << dist[H - 1][W - 1] << endl;
return 0;
}