QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#49556#4412. Boss RushWinnerWA 1894ms31104kbC++112.5kb2022-09-21 23:17:502022-09-21 23:17:52

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 23:17:52]
  • 评测
  • 测评结果:WA
  • 用时:1894ms
  • 内存:31104kb
  • [2022-09-21 23:17:50]
  • 提交

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], f[N];
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 i, int x, int y, int mid){
    int asd = min((int)node[y].size(), mid - line[x].l);
    f[i] = max(f[i], f[x] + sum[y][asd]);
    return f[i] >= H;
}

bool findlen(int x, int mid){
//     cout << "x : " <<x << " " << line[x].r << endl;
    return line[x].r <= mid;
}

bool check(int mid){
    for(int i = 0; i < 1 << n; i++){
        dp[i] = false;
        f[i] = 0;
    }
    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(i, 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;
        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;
            }
        }
        init();
        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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1894ms
memory: 31104kb

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:

367
575
593
249
396
347
263
687
321
579
467
525
468
512
344
684
358
471
507
138
165
292
336
181
354
210
83
179
433
227
232
244
373
426
326
252
139
152
285
138
383
263
135
195
354
129
279
210
173
279
438
153
574
305
356
456
213
285
274
418
285
491
324
385
463
450
273
429
332
426
137
273
307
412
200
1...

result:

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