結果

問題 No.2542 Yokan for Two
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-24 21:44:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 955 bytes
コンパイル時間 2,670 ms
コンパイル使用メモリ 213,784 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2023-11-24 21:44:06
合計ジャッジ時間 6,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 32 ms
6,676 KB
testcase_04 AC 26 ms
6,676 KB
testcase_05 AC 63 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 114 ms
7,936 KB
testcase_08 AC 30 ms
6,676 KB
testcase_09 AC 109 ms
7,808 KB
testcase_10 AC 14 ms
6,676 KB
testcase_11 AC 19 ms
6,676 KB
testcase_12 AC 49 ms
6,676 KB
testcase_13 AC 12 ms
6,676 KB
testcase_14 AC 94 ms
8,192 KB
testcase_15 AC 104 ms
8,448 KB
testcase_16 AC 99 ms
8,320 KB
testcase_17 AC 94 ms
8,064 KB
testcase_18 AC 104 ms
8,576 KB
testcase_19 AC 56 ms
6,676 KB
testcase_20 AC 50 ms
6,676 KB
testcase_21 AC 52 ms
6,676 KB
testcase_22 AC 53 ms
6,676 KB
testcase_23 AC 54 ms
6,676 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 10 ms
6,676 KB
testcase_26 AC 10 ms
6,676 KB
testcase_27 AC 11 ms
6,676 KB
testcase_28 AC 12 ms
6,676 KB
testcase_29 AC 29 ms
6,676 KB
testcase_30 AC 99 ms
8,448 KB
testcase_31 AC 100 ms
8,448 KB
testcase_32 AC 99 ms
8,448 KB
testcase_33 AC 101 ms
8,448 KB
testcase_34 AC 104 ms
8,448 KB
testcase_35 AC 105 ms
8,448 KB
testcase_36 AC 105 ms
8,448 KB
testcase_37 AC 105 ms
8,448 KB
testcase_38 AC 104 ms
8,448 KB
testcase_39 AC 106 ms
8,448 KB
testcase_40 AC 105 ms
8,448 KB
testcase_41 AC 104 ms
8,448 KB
testcase_42 AC 105 ms
8,448 KB
testcase_43 AC 105 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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