結果

問題 No.1283 Extra Fee
ユーザー rokahikou1rokahikou1
提出日時 2020-11-21 12:24:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 2,138 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 182,336 KB
実行使用メモリ 22,032 KB
最終ジャッジ日時 2024-04-27 23:42:43
合計ジャッジ時間 7,046 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 13 ms
6,940 KB
testcase_12 AC 17 ms
6,944 KB
testcase_13 AC 12 ms
6,944 KB
testcase_14 AC 56 ms
6,940 KB
testcase_15 AC 90 ms
7,936 KB
testcase_16 AC 18 ms
6,944 KB
testcase_17 AC 209 ms
21,588 KB
testcase_18 AC 307 ms
18,176 KB
testcase_19 AC 327 ms
18,816 KB
testcase_20 AC 315 ms
17,792 KB
testcase_21 AC 320 ms
18,048 KB
testcase_22 AC 279 ms
16,384 KB
testcase_23 AC 303 ms
19,072 KB
testcase_24 AC 359 ms
19,200 KB
testcase_25 AC 352 ms
19,328 KB
testcase_26 AC 338 ms
19,200 KB
testcase_27 AC 345 ms
19,328 KB
testcase_28 AC 343 ms
19,328 KB
testcase_29 AC 213 ms
22,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:47:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   47 |         auto [cost, pp] = que.top();
      |              ^
main.cpp:49:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   49 |         auto [p, skipped] = pp;
      |              ^
main.cpp:50:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   50 |         auto [x, y] = p;
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};

int main() {
    int N, M;
    cin >> N >> M;
    auto dist = make_vec(N, N, 2, LINF);
    auto check = make_vec(N, N, 0LL);
    rep(i, M) {
        ll h, w, c;
        cin >> h >> w >> c;
        h--, w--;
        check[h][w] = c;
    }
    using State = pair<ll, pair<pii, int>>;
    priority_queue<State, vector<State>, greater<State>> que;
    que.push({0LL, {{0, 0}, 0}});
    dist[0][0][0] = 0;
    while(!que.empty()) {
        auto [cost, pp] = que.top();
        que.pop();
        auto [p, skipped] = pp;
        auto [x, y] = p;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= N || ny < 0 || ny >= N)
                continue;
            if(skipped == 0) {
                if(check[ny][nx] && (dist[ny][nx][0] > cost + 1)) {
                    dist[ny][nx][1] = cost + 1 + check[ny][nx];
                    que.push({cost + 1, {{nx, ny}, 1}});
                }
            }
            if(dist[ny][nx][skipped] > cost + 1 + check[ny][nx]) {
                dist[ny][nx][skipped] = cost + 1 + check[ny][nx];
                que.push({cost + 1 + check[ny][nx], {{nx, ny}, skipped}});
            }
        }
    }
    cout << min(dist[N - 1][N - 1][1], dist[N - 1][N - 1][0]) << endl;
}
0