結果

問題 No.1283 Extra Fee
ユーザー trineutrontrineutron
提出日時 2020-11-21 18:13:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,116 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 210,428 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-30 22:09:20
合計ジャッジ時間 7,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 10 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
            q.emplace(d + board.at(newrow).at(newcolumn), newid);
            if (state == 0) {
                q.emplace(d + 1, newid + n * n);
            }
        }
    }
    cout << cost.at(2 * n * n - 1) << endl;
}
0