結果

問題 No.2542 Yokan for Two
ユーザー MaxdorianMaxdorian
提出日時 2023-11-25 11:14:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 6,485 ms
コンパイル使用メモリ 310,908 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-25 11:14:34
合計ジャッジ時間 7,741 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 6 ms
6,676 KB
testcase_05 AC 6 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 7 ms
6,676 KB
testcase_08 AC 4 ms
6,676 KB
testcase_09 AC 7 ms
6,676 KB
testcase_10 AC 5 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 7 ms
6,676 KB
testcase_15 AC 8 ms
6,676 KB
testcase_16 AC 8 ms
6,676 KB
testcase_17 AC 7 ms
6,676 KB
testcase_18 AC 7 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 7 ms
6,676 KB
testcase_21 AC 7 ms
6,676 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 7 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 4 ms
6,676 KB
testcase_30 AC 8 ms
6,676 KB
testcase_31 AC 7 ms
6,676 KB
testcase_32 AC 7 ms
6,676 KB
testcase_33 AC 8 ms
6,676 KB
testcase_34 AC 7 ms
6,676 KB
testcase_35 AC 7 ms
6,676 KB
testcase_36 AC 8 ms
6,676 KB
testcase_37 AC 7 ms
6,676 KB
testcase_38 AC 8 ms
6,676 KB
testcase_39 AC 7 ms
6,676 KB
testcase_40 AC 8 ms
6,676 KB
testcase_41 AC 7 ms
6,676 KB
testcase_42 AC 7 ms
6,676 KB
testcase_43 AC 7 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int INF = INT_MAX / 2;
const ll LINF = 1LL << 60;
const vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
using mint = modint998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l, n;
  cin >> l >> n;
  vector<int> x;
  int pos = 0;
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    x.push_back(val - pos);
    pos = val;
  }
  x.push_back(l - pos);
  bitset<300010> dp, dp2;
  const int base = 150000;
  dp[base + x[0]] = 1;
  for (int i = 1; i < n + 1; i++) {
    bitset<300010> nxt, nxt2;
    nxt |= (dp << x[i]);
    nxt |= (dp2 << x[i]);
    nxt2 |= (dp >> x[i]);
    nxt2 |= (dp2 >> x[i]);
    swap(dp, nxt);
    swap(dp2, nxt2);
  }
  int ans = INF;
  for (int i = 0; i <= 300009; i++) {
    if (!dp2[i]) {
      continue;
    }
    chmin(ans, abs(base - i));
  }
  cout << ans << '\n';
  return 0;
}
0