結果

問題 No.2656 XOR Slimes
ユーザー t98slider
提出日時 2024-03-01 21:52:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 196,192 KB
最終ジャッジ日時 2025-02-19 22:29:39
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n), a(n);
    cin >> x >> a;
    vector<int> s(n + 1);
    for(int i = 0; i < n; i++){
        s[i + 1] = s[i] ^ a[i];
    }

    vector<long long> dp(n + 1, 1ll << 60);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            dp[j + 1] = min(dp[j + 1], dp[i] + (s[j + 1] ^ s[i]) + x[j] - x[i]);
        }
    }
    cout << dp[n] << '\n';
}
0