結果

問題 No.2542 Yokan for Two
ユーザー MagentorMagentor
提出日時 2023-11-24 22:40:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,485 bytes
コンパイル時間 5,928 ms
コンパイル使用メモリ 310,392 KB
実行使用メモリ 43,112 KB
最終ジャッジ日時 2023-11-24 22:40:54
合計ジャッジ時間 7,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 16 ms
16,032 KB
testcase_04 AC 13 ms
11,032 KB
testcase_05 AC 27 ms
22,892 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 46 ms
38,104 KB
testcase_08 AC 17 ms
13,256 KB
testcase_09 AC 44 ms
37,068 KB
testcase_10 AC 8 ms
7,708 KB
testcase_11 AC 10 ms
8,768 KB
testcase_12 AC 22 ms
18,044 KB
testcase_13 AC 8 ms
7,040 KB
testcase_14 AC 42 ms
40,584 KB
testcase_15 AC 45 ms
42,360 KB
testcase_16 AC 43 ms
41,372 KB
testcase_17 AC 41 ms
39,912 KB
testcase_18 AC 45 ms
43,112 KB
testcase_19 AC 26 ms
24,852 KB
testcase_20 AC 24 ms
23,148 KB
testcase_21 AC 24 ms
23,204 KB
testcase_22 AC 24 ms
23,832 KB
testcase_23 AC 25 ms
23,980 KB
testcase_24 AC 6 ms
6,676 KB
testcase_25 AC 7 ms
8,220 KB
testcase_26 AC 7 ms
8,220 KB
testcase_27 AC 8 ms
8,608 KB
testcase_28 AC 9 ms
9,000 KB
testcase_29 AC 14 ms
14,080 KB
testcase_30 AC 43 ms
42,988 KB
testcase_31 AC 43 ms
42,988 KB
testcase_32 AC 44 ms
42,988 KB
testcase_33 AC 45 ms
42,988 KB
testcase_34 AC 45 ms
42,988 KB
testcase_35 AC 46 ms
42,988 KB
testcase_36 AC 45 ms
42,988 KB
testcase_37 AC 45 ms
42,988 KB
testcase_38 AC 46 ms
42,988 KB
testcase_39 AC 46 ms
42,988 KB
testcase_40 AC 46 ms
42,988 KB
testcase_41 AC 45 ms
42,988 KB
testcase_42 AC 45 ms
42,988 KB
testcase_43 AC 45 ms
42,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
template <typename T>
void input(vector<T> &v){
 rep(i,v.size()){cin>>v[i];}
  return;
}
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll POW(ll a,ll n){
  long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
int main() {
	ll n,l;cin>>l>>n;
	vector<ll> t(n+2,0);
	t[n+1] = l;
	rep(i,n){cin>>t[i+1];}
	ll f = l+3;
 bool dp[n+2][2*l+3][2];//who / parity
 rep(i,n+2){rep(j,2*l+3){rep(k,2){dp[i][j][k] = false;}}}
 dp[0][f][0] = true;
 rep(i,n+1){rep(j,2*l+3){
 ll y = t[i+1]-t[i];	
 if(dp[i][j][0]){if(2*l+3>j+y){dp[i+1][j+y][0] = true;}
 if(0<=j-y&&i!=0){dp[i+1][j-y][1] = true;}}
  if(dp[i][j][1]){if(2*l+3>j+y){dp[i+1][j+y][0] = true;}
 if(0<=j-y){dp[i+1][j-y][1] = true;}}
 
 }}
 ll mn = 9999999999999LL;
 rep(i,2*l+3){if(dp[n+1][i][1]){mn=min(mn,abs(i-f));}}

 cout<<mn;
}
0