結果

問題 No.2542 Yokan for Two
ユーザー 👑 Nachia
提出日時 2023-11-16 01:02:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 77,732 KB
最終ジャッジ日時 2025-02-17 22:13:24
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(i64 i=0; i<(i64)(n); i++)
#define repr(i,n) for(i64 i=(i64)(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int L; cin >> L;
    int N; cin >> N; N++;
    vector<int> X(N); rep(i,N-1) cin >> X[i];
    X[N-1] = L;
    for(int i=N-1; i>=1; i--) X[i] -= X[i-1];
    vector<int> dp(L+1);
    dp[X[0]] = 1;
    for(int i=1; i<N-1; i++){
        int x = X[i];
        for(int q=L; q>=x; q--) dp[q] |= dp[q-x];
    }
    int ans = L;
    rep(i,L+1) if(dp[i]) ans = min<i64>(ans, abs(i-(L-i)));
    cout << ans << endl;
    return 0;
}
0