結果
問題 | No.2366 登校 |
ユーザー |
![]() |
提出日時 | 2023-06-30 21:46:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,237 ms / 4,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 1,857 ms |
コンパイル使用メモリ | 189,004 KB |
実行使用メモリ | 20,992 KB |
最終ジャッジ日時 | 2024-06-12 07:48:45 |
合計ジャッジ時間 | 9,034 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>using namespace std;const long long INF = 1000000000000000;vector<int> dx = {1, 0, -1, 0};vector<int> dy = {0, 1, 0, -1};int main(){int N, M, K, T;cin >> N >> M >> K >> T;vector<int> A(K), B(K), C(K), D(K);for (int i = 0; i < K; i++){cin >> A[i] >> B[i] >> C[i] >> D[i];A[i]--;B[i]--;}if (T >= N + M - 2){cout << 0 << endl;} else {vector<vector<int>> id(N, vector<int>(M, -1));for (int i = 0; i < K; i++){id[A[i]][B[i]] = i;}int T2 = (N + M) * 2 + 1;vector<vector<vector<long long>>> d(T2, vector<vector<long long>>(N, vector<long long>(M, INF)));priority_queue<tuple<long long, int, int, int>, vector<tuple<long long, int, int, int>>, greater<tuple<long long, int, int, int>>> pq;pq.push(make_tuple(0, N + M, 0, 0));while (!pq.empty()){long long c = get<0>(pq.top());int t = get<1>(pq.top());int x = get<2>(pq.top());int y = get<3>(pq.top());pq.pop();if (d[t][x][y] == INF){d[t][x][y] = c;if (id[x][y] != -1){int t2 = max(t - C[id[x][y]] + 1, 0);if (d[t2][x][y] == INF){pq.push(make_tuple(c + D[id[x][y]], t2, x, y));}}if (t < T2 - 1){for (int i = 0; i < 4; i++){int x2 = x + dx[i];int y2 = y + dy[i];if (0 <= x2 && x2 < N && 0 <= y2 && y2 < M){if (d[t + 1][x2][y2] == INF){pq.push(make_tuple(c, t + 1, x2, y2));}}}}}}long long ans = INF;for (int i = -(N + M); i <= T; i++){ans = min(ans, d[N + M + i][N - 1][M - 1]);}if (ans == INF){cout << -1 << endl;} else {cout << ans << endl;}}}