結果
問題 |
No.867 避難経路
|
ユーザー |
![]() |
提出日時 | 2019-08-17 00:02:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,806 bytes |
コンパイル時間 | 1,257 ms |
コンパイル使用メモリ | 96,020 KB |
実行使用メモリ | 14,464 KB |
最終ジャッジ日時 | 2024-09-23 04:10:38 |
合計ジャッジ時間 | 11,911 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | WA * 15 OLE * 1 -- * 25 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; typedef long long ll; int h, w; vector<vector<int>> ban; vector<vector<vector<pair<ll, ll>>>> dp; void bfs(vector<ll> start) { priority_queue<vector<ll>, vector<vector<ll>>, greater<>> que; que.push(start); vector<int> mx{1, -1, 0, 0}; vector<int> my{0, 0, 1, -1}; while (true) { if (que.empty())break; vector<ll> now = que.top(); que.pop(); auto &v = dp[now[2]][now[3]]; if (now[1] >= v[v.size() - 1].second)continue; v.push_back({now[0], now[1]}); for (int i = 0; i < 4; i++) { int ax = now[2] + mx[i]; int ay = now[3] + my[i]; if (0 <= ax && ax < h && 0 <= ay && ay < w) { auto nv = dp[ax][ay]; if (now[1] + ban[ax][ay] < nv[nv.size() - 1].second) que.push({now[0] + 1, now[1] + ban[ax][ay], ax, ay}); } } } } int main() { int gx, gy; cin >> h >> w >> gx >> gy; gx--; gy--; ban = vector<vector<int>>(h, vector<int>(w)); for (int i = 0; i < h; i++) for (int j = 0; j < w; j++)cin >> ban[i][j]; dp = vector<vector<vector<pair<ll, ll>>>> (h, vector<vector<pair<ll, ll>>>(w, vector<pair<ll, ll>>{{0, 1145141919810364}})); bfs({1, ban[gx][gy], gx, gy}); int q; cin >> q; for (int i = 0; i < q; i++) { ll x, y, k; cin >> x >> y >> k; x--; y--; ll ret = 1145141919810364364; for (auto usi:dp[x][y]) { cout << k * k << endl; cout << k * k * usi.first << endl; ret = min(ret, k * k * usi.first + usi.second); } cout << ret << endl; } return 0; }