QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93919#4412. Boss Rushkatoli#AC ✓3379ms15532kbC++141.1kb2023-04-03 22:30:282023-04-03 22:30:32

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-03 22:30:32]
  • 评测
  • 测评结果:AC
  • 用时:3379ms
  • 内存:15532kb
  • [2023-04-03 22:30:28]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll=long long;

const int N=1e5+5;
ll pre[20][N];
int t[20],len[20];
int n;
ll cal(int T){
	vector<ll>dp(1<<n,-1);
	dp[0]=0;
	ll res=0;
	for(int S=1;S<1<<n;++S){
		int tot=0;
		for(int i=0;i<n;++i){
			if(S>>i&1)tot+=t[i];
		}
		for(int i=0;i<n;++i){
			if(S>>i&1){
				int la=S^(1<<i);
				if(dp[la]==-1)continue;
				if(tot-t[i]>T)continue;
				int til=min(len[i]-1,T-(tot-t[i]));
				dp[S]=max(dp[S],dp[la]+pre[i][til]);
			}
		}
		res=max(res,dp[S]);
	}
	return res;
}
signed main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;cin>>T;
	for(;T;T--){
		cin>>n;
		ll h;cin>>h;
		for(int i=0;i<n;++i){
			cin>>t[i]>>len[i];
			for(int j=0;j<len[i];++j){
				cin>>pre[i][j];
				if(j)pre[i][j]+=pre[i][j-1];
			}
		}
		int l=0,r=2e6,ans=-1;
		for(;l<=r;){
			int m=(l+r)>>1;
			if(cal(m)>=h)r=m-1,ans=m;
			else l=m+1;
		}
		cout<<ans<<endl;
	}
	return 0;
}
// init?
// var->0?
// infinite dfs?
// out of bound?
// max_element / min_element?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3379ms
memory: 15532kb

input:

100
10 293367178351
89 52
117480172 951737726 356435682 180765874 775623083 281703307 290364363 366421773 989361116 796791408 389709469 534380525 412173405 463001602 578985383 272777986 833157533 444367936 841474617 472532665 952319800 583679381 924952511 892974994 105808118 171375863 320943603 4870...

output:

368
579
628
249
425
400
296
687
321
579
509
594
475
538
366
694
390
471
524
138
194
292
362
181
357
210
74
190
433
288
241
245
378
426
326
255
134
171
288
138
383
293
135
195
356
129
279
211
168
286
438
152
574
335
421
457
213
315
278
421
285
496
336
385
500
451
300
442
333
433
130
289
329
412
200
1...

result:

ok 100 lines