結果
問題 | No.1283 Extra Fee |
ユーザー | 👑 Nachia |
提出日時 | 2020-11-06 21:53:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 519 ms / 2,000 ms |
コード長 | 1,145 bytes |
コンパイル時間 | 1,685 ms |
コンパイル使用メモリ | 173,852 KB |
実行使用メモリ | 21,908 KB |
最終ジャッジ日時 | 2024-11-16 06:38:36 |
合計ジャッジ時間 | 9,415 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N, M; LL D[500][500]; LL dp[500][500][2]; struct QueueNode { int x, y, t; LL d; }; bool operator<(QueueNode l, QueueNode r) { return l.d > r.d; } int main() { cin >> N >> M; rep(i, N) rep(j, N) D[i][j] = 1; D[0][0] = 0; rep(i, M) { int y, x, c; cin >> y >> x >> c; y--; x--; D[x][y] += c; } rep(i, N) rep(j, N) rep(t, 2) dp[i][j][t] = -1; priority_queue<QueueNode> G; G.push({ N - 1,N - 1,0,0 }); G.push({ N - 1,N - 1,1,0 }); const int dx[4][2] = { {1,0},{-1,0},{0,1},{0,-1} }; while (G.size()) { int x = G.top().x; int y = G.top().y; int t = G.top().t; LL d = G.top().d; G.pop(); if (x < 0 || x >= N) continue; if (y < 0 || y >= N) continue; if (dp[x][y][t] != -1) continue; dp[x][y][t] = d; rep(di, 4) { G.push({ x + dx[di][0], y + dx[di][1], t, d + D[x][y] }); } if (t < 1) { rep(di, 4) { G.push({ x + dx[di][0], y + dx[di][1], t + 1, d + 1 }); } } } LL ans = min(dp[0][0][0], dp[0][0][1]); cout << ans << endl; return 0; }