結果

問題 No.2918 Divide Applicants Fairly
ユーザー miie
提出日時 2024-10-08 22:15:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 516 bytes
コンパイル時間 3,610 ms
コンパイル使用メモリ 251,236 KB
実行使用メモリ 143,232 KB
最終ジャッジ日時 2024-10-08 22:15:30
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	const int sz = 16000005;
	vector<bitset<sz>> dp(n+1);
	for(int i=0; i<n; i++){
		auto ndp = dp;
		for(int j=0; j<=n; j++){
			if(j != 0) ndp[j-1] |= dp[j]>>a[i];
			if(j != n) ndp[j+1] |= dp[j]<<a[i];
		}
		swap(ndp, dp);
		dp[n/2+1].set(sz/2+a[i], 1);
	}
	int ans = 1e9;
	for(int i=0; i<sz; i++){
		if(dp[n/2].test(i)) ans = min(ans, max(sz/2-i, i-sz/2));
	}
	cout << ans << endl;
}
0