結果

問題 No.2542 Yokan for Two
ユーザー 沙耶花沙耶花
提出日時 2023-11-24 21:30:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 4,193 ms
コンパイル使用メモリ 266,116 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-24 21:30:15
合計ジャッジ時間 7,221 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 21 ms
6,676 KB
testcase_04 AC 20 ms
6,676 KB
testcase_05 AC 49 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 89 ms
6,676 KB
testcase_08 AC 23 ms
6,676 KB
testcase_09 AC 86 ms
6,676 KB
testcase_10 AC 11 ms
6,676 KB
testcase_11 AC 15 ms
6,676 KB
testcase_12 AC 39 ms
6,676 KB
testcase_13 AC 9 ms
6,676 KB
testcase_14 AC 65 ms
6,676 KB
testcase_15 AC 74 ms
6,676 KB
testcase_16 AC 71 ms
6,676 KB
testcase_17 AC 66 ms
6,676 KB
testcase_18 AC 73 ms
6,676 KB
testcase_19 AC 39 ms
6,676 KB
testcase_20 AC 34 ms
6,676 KB
testcase_21 AC 35 ms
6,676 KB
testcase_22 AC 36 ms
6,676 KB
testcase_23 AC 38 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 6 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 AC 6 ms
6,676 KB
testcase_28 AC 7 ms
6,676 KB
testcase_29 AC 20 ms
6,676 KB
testcase_30 AC 67 ms
6,676 KB
testcase_31 AC 69 ms
6,676 KB
testcase_32 AC 68 ms
6,676 KB
testcase_33 AC 69 ms
6,676 KB
testcase_34 AC 72 ms
6,676 KB
testcase_35 AC 75 ms
6,676 KB
testcase_36 AC 72 ms
6,676 KB
testcase_37 AC 74 ms
6,676 KB
testcase_38 AC 73 ms
6,676 KB
testcase_39 AC 76 ms
6,676 KB
testcase_40 AC 74 ms
6,676 KB
testcase_41 AC 74 ms
6,676 KB
testcase_42 AC 73 ms
6,676 KB
testcase_43 AC 74 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

int main(){
	
	int L,N;
	cin>>L>>N;
	vector<long long> x(N);
	rep(i,N)cin>>x[i];
	x.push_back(L);
	N++;
	for(int i=N-1;i>=1;i--)x[i] -= x[i-1];
	int A = x[0]-x.back();
	x.erase(x.begin());
	x.pop_back();
	N -= 2;
	vector dp(2,vector<bool>(L*2+5,false));
	int mid = L+1;
	dp[0][mid] = true;
	rep(i,N){
		vector ndp(2,vector<bool>(L*2+5,false));
		rep(j,2){
			rep(k,L*2+5){
				if(dp[j][k]==false)continue;
				
					ndp[0][k+x[i]] = true;
					ndp[1][k+x[i]] = true;
				
					ndp[0][k-x[i]] = true;
					ndp[1][k-x[i]] = true;
				
				
			}
		}
		swap(dp,ndp);
	}
	
	int ans = Inf32;
	rep(i,L*2+5){
		if(dp[0][i])ans = min(ans,abs(i-mid+A));
	}
	
	cout<<ans<<endl;
	return 0;
}
0