QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#49554#4412. Boss RushWinnerWA 2094ms28936kbC++112.4kb2022-09-21 22:35:072022-09-21 22:35:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-21 22:35:08]
  • 评测
  • 测评结果:WA
  • 用时:2094ms
  • 内存:28936kb
  • [2022-09-21 22:35:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1 << 18;
const int M = 3e6;
const int Q = 1e5 + 20;
int T, n;
ll H, sum[20][Q];
bool dp[N];
int t[Q], len[Q];
vector<ll> node[20];
struct LINE{
    int l, r;
    ll sum;
}line[N];

bool cmp(int x, int y){
    return len[x] - t[x] > len[y] - t[y];
}

bool findans(int x, int y, int mid){
    ll res = line[x].sum;
    int asd = min((int)node[y].size(), mid - line[x].l);
    res += sum[y][asd];
    return res >= H;
}

bool findlen(int x, int mid){
    return line[x].r <= mid;
}

bool check(int mid){
    for(int i = 0; i < 1 << n; i++){
        dp[i] = false;
    }
    dp[0] = true;
    for(int i = 1; i < 1 << n; i++){
        for(int j = 0; j < n; j++){
            if(i >> j & 1){
                int res = i ^ (1 << j);
                if(!dp[res]) continue;
                if(findans(res, j + 1, mid)) return true;
                if(findlen(i, mid)) dp[i] = true;
            }
        }
    }
    return false;
}

void init(){
    for(int xx = 0; xx < 1 << n; xx++){
        int x = xx;
        ll res = 0;
        vector<int> id;
        int qwe = 1;
        while(x){
            if(x & 1){
                id.push_back(qwe);
                res += sum[qwe][0];
            }
            x >>= 1;
            qwe++;
        }
        sort(id.begin(), id.end(), cmp);
        int l = 0, r = 0;
        for(auto it: id){
            r = max(r, l + len[it]);
            l += t[it];
        }
        line[xx] = {l, r, res};
    }
}

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin >> T;
	while(T--){
		cin >> n >> H;
        init();
        for(int i = 1; i <= n; i++){
            node[i].clear();
            sum[i][0] = sum[i][1] = 0;
            cin >> t[i] >> len[i];
            for(int j = 1; j <= len[i]; j++){
                ll x;
                cin >> x;
                node[i].push_back(x);
                sum[i][0] += x;
                if(j == 1) sum[i][1] = x;
                else sum[i][j] = sum[i][j - 1] + x;
            }
        }
        int ans = -1;
        int l = 1, r = M;
        while(l <= r){
            int mid = (l + r) / 2;
            if(check(mid)){
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        if(ans != - 1) ans --;
        cout << ans << endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2094ms
memory: 28936kb

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:

-1
502
558
302
383
320
308
647
296
593
460
576
442
556
349
612
346
428
387
367
139
165
381
287
251
230
75
128
-1
178
182
287
265
-1
289
119
278
134
302
140
368
145
226
135
386
203
141
337
127
260
382
251
414
302
519
495
138
107
-1
252
273
395
293
404
566
315
362
235
229
-1
138
270
268
522
136
140
48...

result:

wrong answer 1st lines differ - expected: '368', found: '-1'