結果

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

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    vector<long long> X(N),A(N);
    for(auto &x : X) cin >> x;
    for(auto &a : A) cin >> a;

    vector<long long> Xor = A;
    for(int i=1; i<N; i++) Xor.at(i) ^= Xor.at(i-1);

    vector<long long> dp(N+1,1e18);
    dp.at(0) = 0;
    for(int i=0; i<N; i++){
        dp.at(i+1) = min(dp.at(i+1),dp.at(i)+A.at(i));
        for(int k=i+1; k<N; k++){
            long long plus = X.at(k)-X.at(i);
            long long plus2 = Xor.at(k);
            if(i) plus2 ^= Xor.at(i-1);
            dp.at(k+1) = min(dp.at(k+1),dp.at(i)+plus+plus2);
        }
    }
    cout << dp.back() << endl;
}
0