結果

問題 No.2656 XOR Slimes
ユーザー SnowBeenDidingSnowBeenDiding
提出日時 2024-03-01 21:34:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 957 ms / 2,000 ms
コード長 2,236 bytes
コンパイル時間 5,462 ms
コンパイル使用メモリ 324,768 KB
実行使用メモリ 218,940 KB
最終ジャッジ日時 2024-03-01 21:35:07
合計ジャッジ時間 55,235 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 935 ms
214,892 KB
testcase_09 AC 948 ms
215,864 KB
testcase_10 AC 939 ms
215,916 KB
testcase_11 AC 919 ms
215,916 KB
testcase_12 AC 916 ms
215,916 KB
testcase_13 AC 942 ms
215,864 KB
testcase_14 AC 941 ms
215,916 KB
testcase_15 AC 934 ms
214,840 KB
testcase_16 AC 922 ms
215,864 KB
testcase_17 AC 948 ms
215,864 KB
testcase_18 AC 931 ms
214,892 KB
testcase_19 AC 951 ms
215,864 KB
testcase_20 AC 916 ms
215,864 KB
testcase_21 AC 916 ms
215,864 KB
testcase_22 AC 938 ms
215,916 KB
testcase_23 AC 940 ms
215,864 KB
testcase_24 AC 923 ms
215,864 KB
testcase_25 AC 927 ms
215,864 KB
testcase_26 AC 941 ms
215,916 KB
testcase_27 AC 938 ms
215,916 KB
testcase_28 AC 920 ms
215,864 KB
testcase_29 AC 934 ms
215,916 KB
testcase_30 AC 942 ms
215,864 KB
testcase_31 AC 951 ms
215,864 KB
testcase_32 AC 932 ms
215,864 KB
testcase_33 AC 928 ms
215,916 KB
testcase_34 AC 943 ms
215,864 KB
testcase_35 AC 944 ms
215,916 KB
testcase_36 AC 931 ms
214,892 KB
testcase_37 AC 898 ms
214,892 KB
testcase_38 AC 940 ms
218,940 KB
testcase_39 AC 950 ms
215,864 KB
testcase_40 AC 953 ms
215,916 KB
testcase_41 AC 927 ms
218,736 KB
testcase_42 AC 917 ms
215,916 KB
testcase_43 AC 938 ms
215,864 KB
testcase_44 AC 948 ms
215,916 KB
testcase_45 AC 940 ms
215,916 KB
testcase_46 AC 919 ms
215,916 KB
testcase_47 AC 939 ms
215,864 KB
testcase_48 AC 944 ms
215,916 KB
testcase_49 AC 918 ms
215,916 KB
testcase_50 AC 918 ms
215,916 KB
testcase_51 AC 957 ms
215,864 KB
testcase_52 AC 940 ms
215,916 KB
testcase_53 AC 917 ms
215,916 KB
testcase_54 AC 917 ms
214,892 KB
testcase_55 AC 939 ms
215,916 KB
testcase_56 AC 943 ms
215,864 KB
testcase_57 AC 914 ms
215,864 KB
testcase_58 AC 927 ms
214,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace std;
using namespace atcoder;

typedef long long ll;

template <typename T>
struct Graph {
    struct edge {
        int to;
        T cost;
    };
    int N;
    vector<vector<edge>> G;
    vector<T> dist;
    vector<int> prever;

    Graph(int n) { init(n); }
    T inf() {
        if (is_same_v<T, int>)
            return 1e9;
        else
            return 1e18;
    }
    T zero() { return T(0); }

    void init(int n) {
        N = n;
        G.resize(N);
        dist.resize(N, inf());
    }
    void add_edge(int s, int t, T cost) {
        edge e;
        e.to = t, e.cost = cost;
        G[s].push_back(e);
    }
    void dijkstra(int s) {
        rep(i, 0, N) dist[i] = inf();
        prever = vector<int>(N, -1);
        dist[s] = zero();
        priority_queue<pair<T, int>, vector<pair<T, int>>,
                       greater<pair<T, int>>>
            q;
        q.push({zero(), s});
        while (!q.empty()) {
            int now;
            T nowdist;
            tie(nowdist, now) = q.top();
            q.pop();
            if (dist[now] < nowdist) continue;
            for (auto e : G[now]) {
                T nextdist = nowdist + e.cost;  // 次の頂点への距離
                if (dist[e.to] > nextdist) {
                    prever[e.to] = now;
                    dist[e.to] = nextdist;
                    q.push({dist[e.to], e.to});
                }
            }
        }
    }

    vector<int> get_path(int t) {  // tへの最短路構築
        if (dist[t] >= inf()) return {-1};
        vector<int> path;
        for (; t != -1; t = prever[t]) {
            path.push_back(t);
        }
        reverse(path.begin(), path.end());
        return path;
    }
};

ll op(ll a, ll b) { return a ^ b; }
ll e() { return 0; }

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), x(n);
    rep(i, 0, n) cin >> x[i];
    rep(i, 0, n) cin >> a[i];
    Graph<ll> gr(n + 1);
    segtree<ll, op, e> st(a);
    rep(i, 0, n) rep(j, i + 1, n + 1) {
        gr.add_edge(i, j, st.prod(i, j) + abs(x[i] - x[j - 1]));
    }
    gr.dijkstra(0);
    cout << gr.dist[n] << endl;
}
0