結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-11-21 18:15:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,212 bytes |
| コンパイル時間 | 2,691 ms |
| コンパイル使用メモリ | 207,380 KB |
| 最終ジャッジ日時 | 2025-01-16 04:06:25 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 TLE * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using grid = vector<vector<int64_t>>;
vector<int> dx{1, 0, -1, 0}, dy{0, 1, 0, -1};
int main() {
int n, m;
cin >> n >> m;
grid board(n, vector<int64_t>(n, 1));
for (int i = 0; i < m; i++) {
int h, w, c;
cin >> h >> w >> c;
board.at(h - 1).at(w - 1) += c;
}
vector<int64_t> cost(2 * n * n, 1L << 60);
priority_queue<pair<int64_t, int>> q;
q.emplace(0, 0);
while (not q.empty()) {
auto [d, id] = q.top();
q.pop();
if (d >= cost.at(id)) continue;
cost.at(id) = d;
int state = id / (n * n), row = id / n % n, column = id % n;
for (int i = 0; i < 4; i++) {
int newrow = row + dx[i], newcolumn = column + dy[i], newid = id + n * dx[i] + dy[i];
if (newrow < 0 or n <= newrow or newcolumn < 0 or n <= newcolumn) continue;
int64_t newd = d + board.at(newrow).at(newcolumn);
if (newd < cost.at(newid)) q.emplace(newd, newid);
if (state == 0) {
if (d + 1 < cost.at(newid + n * n)) q.emplace(d + 1, newid + n * n);
}
}
}
cout << cost.at(2 * n * n - 1) << endl;
}
trineutron