結果

問題 No.2542 Yokan for Two
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-12-21 10:10:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 753 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 3,989 ms
コンパイル使用メモリ 210,112 KB
実行使用メモリ 17,468 KB
最終ジャッジ日時 2023-12-21 10:10:57
合計ジャッジ時間 23,168 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 217 ms
17,464 KB
testcase_04 AC 128 ms
6,724 KB
testcase_05 AC 355 ms
15,392 KB
testcase_06 AC 17 ms
10,624 KB
testcase_07 AC 585 ms
16,316 KB
testcase_08 AC 168 ms
14,648 KB
testcase_09 AC 597 ms
16,188 KB
testcase_10 AC 73 ms
6,724 KB
testcase_11 AC 91 ms
6,676 KB
testcase_12 AC 249 ms
14,904 KB
testcase_13 AC 62 ms
6,676 KB
testcase_14 AC 656 ms
16,444 KB
testcase_15 AC 665 ms
17,084 KB
testcase_16 AC 672 ms
16,700 KB
testcase_17 AC 642 ms
16,188 KB
testcase_18 AC 674 ms
17,340 KB
testcase_19 AC 365 ms
10,904 KB
testcase_20 AC 357 ms
10,340 KB
testcase_21 AC 331 ms
10,356 KB
testcase_22 AC 344 ms
10,516 KB
testcase_23 AC 367 ms
10,552 KB
testcase_24 AC 57 ms
17,464 KB
testcase_25 AC 83 ms
17,464 KB
testcase_26 AC 83 ms
17,464 KB
testcase_27 AC 90 ms
17,464 KB
testcase_28 AC 97 ms
17,464 KB
testcase_29 AC 185 ms
17,464 KB
testcase_30 AC 731 ms
17,468 KB
testcase_31 AC 671 ms
17,468 KB
testcase_32 AC 698 ms
17,468 KB
testcase_33 AC 668 ms
17,468 KB
testcase_34 AC 697 ms
17,468 KB
testcase_35 AC 753 ms
17,468 KB
testcase_36 AC 668 ms
17,468 KB
testcase_37 AC 694 ms
17,468 KB
testcase_38 AC 667 ms
17,468 KB
testcase_39 AC 697 ms
17,468 KB
testcase_40 AC 672 ms
17,468 KB
testcase_41 AC 697 ms
17,468 KB
testcase_42 AC 699 ms
17,468 KB
testcase_43 AC 675 ms
17,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int L, N, ans=1e9;
    cin >> L >> N;
    vector<int> x(N+1);
    for (int i=1; i<=N; i++) cin >> x[i];

    vector dp(vector(L+1, vector<bool>(2)));
    dp[0][0] = 1;
    for (int i=1; i<=N; i++){
        vector pd(vector(L+1, vector<bool>(2)));
        for (int j=0; j<=L; j++){
            if (j-(x[i]-x[i-1])>=0){
                pd[j][0] = pd[j][0] | dp[j-(x[i]-x[i-1])][0];
                pd[j][1] = pd[j][1] | dp[j-(x[i]-x[i-1])][0];
            }
            pd[j][0] = pd[j][0] | dp[j][1];
            pd[j][1] = pd[j][1] | dp[j][1];
        }
        swap(dp, pd);
    }

    for (int i=0; i<=L; i++){
        if (dp[i][0]) ans = min(ans, abs(i-(L-i)));
    }

    cout << ans << endl;

    return 0;
}
0