結果

問題 No.2656 XOR Slimes
ユーザー KKT89KKT89
提出日時 2024-03-01 21:30:13
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 215,480 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-29 13:32:23
合計ジャッジ時間 4,458 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> x(n), a(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<ll> dp(n+1, 2e18);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        ll dif = 0;
        ll cur = 0;
        for (int j = i; j < n; ++j) {
            cur ^= a[j];
            dp[j+1] = min(dp[j+1], dp[i]+cur+dif);
            if (j+1 < n) dif += x[j+1] - x[j];
        }
    }
    cout << dp[n] << endl;
}
0