結果
問題 | No.2542 Yokan for Two |
ユーザー | Magentor |
提出日時 | 2023-11-24 22:40:45 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 2,485 bytes |
コンパイル時間 | 5,276 ms |
コンパイル使用メモリ | 309,452 KB |
実行使用メモリ | 43,008 KB |
最終ジャッジ日時 | 2024-09-26 09:40:13 |
合計ジャッジ時間 | 8,322 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 21 ms
16,000 KB |
testcase_04 | AC | 15 ms
11,008 KB |
testcase_05 | AC | 35 ms
22,784 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 61 ms
38,016 KB |
testcase_08 | AC | 20 ms
13,184 KB |
testcase_09 | AC | 61 ms
36,992 KB |
testcase_10 | AC | 10 ms
7,552 KB |
testcase_11 | AC | 12 ms
8,704 KB |
testcase_12 | AC | 29 ms
17,920 KB |
testcase_13 | AC | 9 ms
6,912 KB |
testcase_14 | AC | 58 ms
40,576 KB |
testcase_15 | AC | 63 ms
42,240 KB |
testcase_16 | AC | 62 ms
41,344 KB |
testcase_17 | AC | 58 ms
39,936 KB |
testcase_18 | AC | 63 ms
43,008 KB |
testcase_19 | AC | 35 ms
24,832 KB |
testcase_20 | AC | 32 ms
23,168 KB |
testcase_21 | AC | 32 ms
23,168 KB |
testcase_22 | AC | 33 ms
23,808 KB |
testcase_23 | AC | 34 ms
23,936 KB |
testcase_24 | AC | 7 ms
6,528 KB |
testcase_25 | AC | 9 ms
8,192 KB |
testcase_26 | AC | 9 ms
8,192 KB |
testcase_27 | AC | 9 ms
8,576 KB |
testcase_28 | AC | 10 ms
8,832 KB |
testcase_29 | AC | 19 ms
13,952 KB |
testcase_30 | AC | 62 ms
43,008 KB |
testcase_31 | AC | 62 ms
42,880 KB |
testcase_32 | AC | 62 ms
42,880 KB |
testcase_33 | AC | 63 ms
42,752 KB |
testcase_34 | AC | 63 ms
42,880 KB |
testcase_35 | AC | 64 ms
42,880 KB |
testcase_36 | AC | 63 ms
42,880 KB |
testcase_37 | AC | 64 ms
42,880 KB |
testcase_38 | AC | 63 ms
42,880 KB |
testcase_39 | AC | 64 ms
43,008 KB |
testcase_40 | AC | 64 ms
42,880 KB |
testcase_41 | AC | 63 ms
42,880 KB |
testcase_42 | AC | 63 ms
42,880 KB |
testcase_43 | AC | 64 ms
42,880 KB |
ソースコード
#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; }