結果

問題 No.733 分身並列コーディング
コンテスト
ユーザー vjudge1
提出日時 2026-01-25 12:46:39
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 288 ms / 1,500 ms
コード長 607 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,300 ms
コンパイル使用メモリ 184,328 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-25 12:46:52
合計ジャッジ時間 7,023 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200010;
const int INF=0x3f3f3f3f3f3f3f3f;
int T,n;
int dp[1<<17];
int t[N];
int sum[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>T>>n;
	for(int i=1;i<=n;i++)cin>>t[i];
	for(int S=1;S<(1<<n);S++){
		for(int i=1;i<=n;i++){
			if((S>>(i-1)&1))sum[S]+=t[i];
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int S=1;S<(1<<n);S++){
		if(sum[S]<=T){
			dp[S]=1;
			continue;
		}
		for(int TT=S&(S-1);TT;TT=(TT-1)&S)if(sum[S^TT]<=T)dp[S]=min(dp[S],dp[TT]+1);
	}
	cout<<dp[(1<<n)-1]<<"\n";
	return 0;
}
0