結果

問題 No.2542 Yokan for Two
ユーザー ococonomy1ococonomy1
提出日時 2023-11-24 22:27:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 123,916 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-11-24 22:27:59
合計ジャッジ時間 4,380 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 4 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 22 ms
6,676 KB
testcase_04 AC 51 ms
7,296 KB
testcase_05 AC 43 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 73 ms
8,064 KB
testcase_08 AC 24 ms
6,676 KB
testcase_09 AC 70 ms
7,936 KB
testcase_10 AC 28 ms
6,676 KB
testcase_11 AC 38 ms
6,676 KB
testcase_12 AC 35 ms
6,676 KB
testcase_13 AC 28 ms
6,676 KB
testcase_14 AC 66 ms
8,320 KB
testcase_15 AC 69 ms
8,320 KB
testcase_16 AC 68 ms
8,320 KB
testcase_17 AC 67 ms
8,320 KB
testcase_18 AC 68 ms
8,320 KB
testcase_19 AC 63 ms
8,320 KB
testcase_20 AC 63 ms
8,320 KB
testcase_21 AC 65 ms
8,320 KB
testcase_22 AC 63 ms
8,320 KB
testcase_23 AC 65 ms
8,320 KB
testcase_24 AC 6 ms
6,676 KB
testcase_25 AC 8 ms
6,676 KB
testcase_26 AC 8 ms
6,676 KB
testcase_27 AC 9 ms
6,676 KB
testcase_28 AC 10 ms
6,676 KB
testcase_29 AC 20 ms
6,676 KB
testcase_30 AC 66 ms
8,320 KB
testcase_31 AC 66 ms
8,320 KB
testcase_32 AC 65 ms
8,320 KB
testcase_33 AC 66 ms
8,320 KB
testcase_34 AC 68 ms
8,320 KB
testcase_35 AC 68 ms
8,320 KB
testcase_36 AC 67 ms
8,320 KB
testcase_37 AC 69 ms
8,320 KB
testcase_38 AC 68 ms
8,320 KB
testcase_39 AC 69 ms
8,320 KB
testcase_40 AC 67 ms
8,320 KB
testcase_41 AC 68 ms
8,320 KB
testcase_42 AC 68 ms
8,320 KB
testcase_43 AC 69 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <unordered_map>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TIME_LIMIT 1980000
#define el '\n'
#define El '\n'

#define MULTI_TEST_CASE false
void solve(void) {
    int l,n;
    cin >> l >> n;
    vector<int> x(n);
    vector<bool> kireme(l,false);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    x.push_back(l);
    n++;
    //dp0[i] := 赤側を選んでる時の、i番目の切れ目まで見た時のありえるA-Bの値の集合
    vector<bitset<200002>> dp0(n + 1),dp1(n + 1);
    const int m = 100000;
    dp0[0][0 + m] = true;
    for(int i = 0; i < n; i++){
        int dif = x[i] - (i == 0 ? 0 : x[i - 1]);
        for(int j = 0; j < 200002; j++){
            if(!dp0[i][j])continue;
            //cerr << j << ' ' << dif << el;
            dp0[i + 1][j + dif] = true;
            if(i != 0)dp1[i + 1][j - dif] = true;
        }
        for(int j = 0; j < 200002; j++){
            if(!dp1[i][j])continue;
            dp0[i + 1][j + dif] = true;
            dp1[i + 1][j - dif] = true;
        }
    }
    int ans = INT_MAX;
    for(int j = 0; j < 200002; j++){
        if(dp1[n][j])ans = min(ans,abs(j - m));
    }
    cout << ans << el;
    return;
}

void calc(void) {
    return;
}

signed main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE) cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
0