結果

問題 No.2542 Yokan for Two
ユーザー momoyuumomoyuu
提出日時 2023-11-24 21:34:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 126,124 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-24 21:34:48
合計ジャッジ時間 2,809 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 6 ms
6,676 KB
testcase_10 AC 4 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 5 ms
6,676 KB
testcase_15 AC 6 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 6 ms
6,676 KB
testcase_21 AC 6 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 6 ms
6,676 KB
testcase_31 AC 6 ms
6,676 KB
testcase_32 AC 6 ms
6,676 KB
testcase_33 AC 6 ms
6,676 KB
testcase_34 AC 6 ms
6,676 KB
testcase_35 AC 6 ms
6,676 KB
testcase_36 AC 6 ms
6,676 KB
testcase_37 AC 6 ms
6,676 KB
testcase_38 AC 6 ms
6,676 KB
testcase_39 AC 6 ms
6,676 KB
testcase_40 AC 6 ms
6,676 KB
testcase_41 AC 6 ms
6,676 KB
testcase_42 AC 6 ms
6,676 KB
testcase_43 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0