結果
| 問題 | No.2542 Yokan for Two | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-11-24 21:44:00 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 134 ms / 2,000 ms | 
| コード長 | 955 bytes | 
| コンパイル時間 | 1,880 ms | 
| コンパイル使用メモリ | 206,980 KB | 
| 最終ジャッジ日時 | 2025-02-17 23:56:24 | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 40 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int L,N; cin >> L >> N;
    vector<long long> X(1);
    for(int i=0; i<N; i++){
        int x; cin >> x;
        X.push_back(x);
    }
    X.push_back(L);
    vector dp(N+2,vector<vector<bool>>(2,vector<bool>(2*L+9,false)));
    dp.at(0).at(0).at(L) = true;
    for(int i=0; i<=N; i++){
        int len = X.at(i+1)-X.at(i);
        if(i == 0){
            dp.at(i+1).at(0).at(L+len) = true;
            continue;
        }
        for(int k=0; k<2; k++) for(int l=0; l<2*L+9; l++){
            if(!dp.at(i).at(k).at(l)) continue;
            if(l+len < 2*L+9) dp.at(i+1).at(0).at(l+len) = true;
            if(l-len >= 0) dp.at(i+1).at(1).at(l-len) = true;
        }
    }
    int answer = 1e9;
    for(int i=0; i<2*L+9; i++){
        if(dp.at(N+1).at(1).at(i)) answer = min(answer,abs(L-i));
    }
    cout << answer << endl;
}
            
            
            
        