結果
| 問題 |
No.2542 Yokan for Two
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-11-24 21:34:45 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 988 bytes |
| コンパイル時間 | 1,294 ms |
| コンパイル使用メモリ | 124,392 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-26 08:57:45 |
| 合計ジャッジ時間 | 2,651 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<cassert>
#include<set>
#include<queue>
#include<cstdint>
#include<unordered_map>
using namespace std;
using ll = long long;
#include<stack>
#include<bitset>
const int mx = 2e5;
using B = bitset<mx>;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll l,n;
cin>>l>>n;
vector<ll> x(n);
for(int i = 0;i<n;i++) cin>>x[i];
vector<B> dp(4);
dp[0].set(0);
ll sum = 0;
vector<ll> d;
d.push_back(x[0]);
for(int i = 1;i<n;i++) d.push_back(x[i]-x[i-1]);
d.push_back(l-x.back());
for(int i = 0;i<d.size();i++){
vector<B> ndp(4);
ndp[0] = (dp[3]);
ndp[1] = (dp[1]<<d[i]) | (dp[0]<<d[i]) | (dp[3]<<d[i]);
ndp[3] = dp[1] | dp[3];
swap(ndp,dp);
}
ll ans = 1e18;
sum = l;
for(int i = 0;i<mx;i++) if(dp[3][i]){
// cout<<i<<endl;
ans = min(ans,abs(sum-2*i));
}
cout<<ans<<endl;
}
momoyuu