QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#598119#4412. Boss Rushship2077#AC ✓1415ms18424kbC++231.1kb2024-09-28 20:34:062024-09-28 20:34:08

Judging History

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

  • [2024-09-28 20:34:08]
  • 评测
  • 测评结果:AC
  • 用时:1415ms
  • 内存:18424kb
  • [2024-09-28 20:34:06]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;
constexpr int M=(1<<18)+5;
int n,H,t[20],len[20],sum[M],dp[M];
vector<int>vec[20];
bool check(int mid){
    for (int sta=0;sta<1<<n;sta++) dp[sta]=0;
    for (int sta=0;sta<1<<n;sta++) if (sum[sta]<=mid)
        for (int i=0;i<n;i++) if (~sta>>i&1)
            dp[sta^1<<i]=max(dp[sta^1<<i],dp[sta]+vec[i][min(len[i],mid-sum[sta])]);
    for (int sta=0;sta<1<<n;sta++)
        if (dp[sta]>=H) return 1;
    return 0;
}
void solve(){ cin>>n>>H;
    for (int i=0;i<n;i++){
        cin>>t[i]>>len[i];
        int sum=0;vec[i]={0};
        for (int j=0;j<len[i];j++){
            int x;cin>>x;sum+=x;
            vec[i].emplace_back(sum);
        }
    }
    for (int sta=1;sta<1<<n;sta++){
        int low=sta&-sta,p=__builtin_ctz(sta);
        sum[sta]=sum[sta^low]+t[p];
    }
    int l=1,r=2e6,ans=0;
    while (l<=r){
        int mid=l+r>>1;
        if (check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans-1<<endl;
}
signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;cin>>T;while (T--) solve();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1415ms
memory: 18424kb

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