結果
| 問題 |
No.867 避難経路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-16 23:30:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,075 bytes |
| コンパイル時間 | 2,016 ms |
| コンパイル使用メモリ | 182,456 KB |
| 実行使用メモリ | 16,640 KB |
| 最終ジャッジ日時 | 2024-09-22 23:03:26 |
| 合計ジャッジ時間 | 23,283 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 WA * 4 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
using namespace std;
using ll = long long;
int dp[50][250][250];
ll ep[250][250];
constexpr ll inf = 1e13;
void chmin(ll &x, ll y) {
x = min(x, y);
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int H, W, GY, GX; cin >> H >> W >> GY >> GX;
GY--; GX--;
vector<vector<int>> A(H, vector<int>(W));
rep(i, H) rep(j, W) cin >> A[i][j];
rep(k, 50) rep(i, 250) rep(j, 250) dp[k][i][j] = 1e9;
dp[0][GY][GX] = A[GY][GX];
const int dy[] = {0, 1, 0, -1};
const int dx[] = {1, 0, -1, 0};
rep(k, 50) {
dp[k][GY][GX] = A[GY][GX] + k*k;
priority_queue<tuple<ll, int, int>> q;
q.emplace(-dp[k][GY][GX], GY, GX);
while (!q.empty()) {
ll d;
int y, x;
tie(d, y, x) = q.top(); q.pop();
if (-d > dp[k][y][x]) continue;
rep(l, 4) {
int ny = y + dy[l];
int nx = x + dx[l];
if (0 <= ny && ny < H && 0 <= nx && nx < W) {
if (dp[k][ny][nx] > dp[k][y][x] + A[ny][nx] + k*k) {
dp[k][ny][nx] = dp[k][y][x] + A[ny][nx] + k*k;
q.emplace(-dp[k][ny][nx], ny, nx);
}
}
}
}
}
rep(i, 250) rep(j, 250) ep[i][j] = 1e18;
ep[GY][GX] = A[GY][GX] + inf;
priority_queue<tuple<ll, int, int>> q;
q.emplace(-ep[GY][GX], GY, GX);
while (!q.empty()) {
ll d;
int y, x;
tie(d, y, x) = q.top(); q.pop();
if (-d > ep[y][x]) continue;
rep(l, 4) {
int ny = y + dy[l];
int nx = x + dx[l];
if (0 <= ny && ny < H && 0 <= nx && nx < W) {
if (ep[ny][nx] > ep[y][x] + A[ny][nx] + inf) {
ep[ny][nx] = ep[y][x] + A[ny][nx] + inf;
q.emplace(-ep[ny][nx], ny, nx);
}
}
}
}
int Q; cin >> Q;
while (Q--) {
int y, x;
ll k; cin >> y >> x >> k; y--; x--;
if (k < 50) {
cout << dp[k][y][x] << '\n';
} else {
ll d = (abs(GY - y) + abs(GX - x) + 1);
cout << ep[y][x] - d * inf + d * k * k << '\n';
}
}
}