結果
問題 | No.2656 XOR Slimes |
ユーザー | otoshigo |
提出日時 | 2024-03-01 22:23:59 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 833 bytes |
コンパイル時間 | 846 ms |
コンパイル使用メモリ | 77,332 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-29 14:29:27 |
合計ジャッジ時間 | 3,357 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 55 |
ソースコード
#include<iostream> #include<algorithm> #include<vector> using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} const ll INF=1LL<<60; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); 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>S(N+1); for(int i=0;i<N;i++)S[i+1]=S[i]^A[i]; vector<ll>dp(N+1,INF); dp[0]=0; for(int i=0;i<N;i++){ for(int j=0;j<=i;j++){ chmin(dp[i+1],dp[j]+(S[i+1]^S[j])+X[i]-X[j]); } } ll ans=dp[N]; cout<<ans<<"\n"; }