結果

問題 No.2542 Yokan for Two
コンテスト
ユーザー maksim
提出日時 2023-11-24 22:21:46
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 564 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,403 ms
コンパイル使用メモリ 182,352 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-13 12:35:32
合計ジャッジ時間 3,412 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define app push_back
const int maxn=2e5+5;
bitset<maxn> b;
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int l,n;cin>>l>>n;
    int a[n];for(int i=0;i<n;++i) cin>>a[i];
    int s=a[0];
    b[0]=1;
    for(int j=1;j<n;++j)
    {
        int diff=a[j]-a[j-1];
        b=b | (b<<diff);
    }
    int res=l;
    for(int s1=0;s1<maxn;++s1)
    {
        if(b[s1])
        {
            res=min(res,abs(l-2*(s+s1)));
        }
    }
    cout<<res;
    return 0;
}
0