結果

問題 No.2656 XOR Slimes
ユーザー Aeren
提出日時 2024-03-01 21:42:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 248,516 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 13:39:54
合計ジャッジ時間 4,576 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n;
	cin >> n;
	vector<int> pos(n), a(n);
	copy_n(istream_iterator<int>(cin), n, pos.begin());
	copy_n(istream_iterator<int>(cin), n, a.begin());
	vector<int> pref(n + 1);
	for(auto i = 0; i < n; ++ i){
		pref[i + 1] = pref[i] ^ a[i];
	}
	const long long inf = 3e18;
	vector<long long> dp(n + 1, inf);
	dp[0] = 0;
	for(auto l = 0; l < n; ++ l){
		for(auto r = l + 1; r <= n; ++ r){
			dp[r] = min(dp[r], dp[l] + (pref[r] ^ pref[l]) + pos[r - 1] - pos[l]);
		}
	}
	cout << dp[n] << "\n";
	return 0;
}

/*

*/
0