QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#819919#4412. Boss RushKevin5307AC ✓2086ms26524kbC++231.8kb2024-12-18 18:20:292024-12-18 18:20:30

Judging History

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

  • [2024-12-18 18:20:30]
  • 评测
  • 测评结果:AC
  • 用时:2086ms
  • 内存:26524kb
  • [2024-12-18 18:20:29]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
vector<ll> d[20],psum[20];
int t[20];
int val[1<<18];
ll dp[1<<18];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc;
	cin>>tc;
	while(tc--)
	{
		int n;
		ll h;
		cin>>n>>h;
		for(int i=0;i<n;i++)
		{
			cin>>t[i];
			int len;
			cin>>len;
			d[i].resize(len);
			psum[i].resize(len+1);
			for(auto &x:d[i]) cin>>x;
			psum[i][0]=0;
			for(int j=0;j<len;j++)
				psum[i][j+1]=psum[i][j]+d[i][j];
		}
		ll tot=0;
		for(int i=0;i<n;i++)
			tot+=psum[i].back();
		if(tot<h)
			cout<<"-1\n";
		else
		{
			for(int i=0;i<(1<<n);i++)
			{
				val[i]=0;
				for(int j=0;j<n;j++) if(i>>j&1)
					val[i]+=t[j];
			}
			int L=0,R=2e6;
			while(L<R)
			{
				int mid=(L+R)/2;
				for(int i=0;i<(1<<n);i++)
					dp[i]=0;
				for(int i=0;i<(1<<n);i++)
					for(int j=0;j<n;j++) if(!(i>>j&1))
					{
						int have=min(sz(d[j]),mid-val[i]+1);
						have=max(have,0);
						dp[i|(1<<j)]=max(dp[i|(1<<j)],dp[i]+psum[j][have]);
					}
				if(dp[(1<<n)-1]>=h)
					R=mid;
				else
					L=mid+1;
			}
			cout<<L<<'\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2086ms
memory: 26524kb

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