結果

問題 No.2542 Yokan for Two
ユーザー shobonvip
提出日時 2023-11-24 21:35:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 4,164 ms
コンパイル使用メモリ 253,012 KB
最終ジャッジ日時 2025-02-17 23:50:24
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
	return lower_bound(X.begin(), X.end(), v) - X.begin();
}

template <typename T>
int bisect_right(vector<T> &X, T v){
	return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----


typedef bitset<3141592> B;

int main(){
	int l, n; cin >> l >> n;
	vector<int> x(n+1);
	int nw = 0;
	rep(i,0,n){
		int y; cin >> y;
		x[i] = y - nw;
		nw = y;
	}
	x[n] = l - nw;
	n++;

	int base = 1500000;
	B dp0;
	B dp1;
	dp0[base + x[0]] = 1;

	rep(i,1,n){
		B ndp0;
		B ndp1;
		ndp0 |= dp0 << x[i];
		ndp0 |= dp1 << x[i];
		ndp1 |= dp0 >> x[i];
		ndp1 |= dp1 >> x[i];		
		dp0 = ndp0;
		dp1 = ndp1;
	}

	int ans = 1e9;
	rep(i,0,3141592){
		if (!dp1[i]) continue;
		chmin(ans, abs(base - i));
	}
	cout << ans << '\n';
}


0