QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#46046#4412. Boss RushmiaomiaoziAC ✓3241ms16928kbC++172.2kb2022-08-24 22:54:382022-08-24 22:54:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-24 22:54:40]
  • 评测
  • 测评结果:AC
  • 用时:3241ms
  • 内存:16928kb
  • [2022-08-24 22:54:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917

#ifndef LOCAL
#define LOG(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long LL;
typedef pair <int, int> PII;

constexpr LL inf = 1e18;
constexpr double EPS = 1e-8;
const double PI = acos(-1);

int multi_cases = 1;

void A_SOUL_AvA () {
    int n;
    LL H;
    cin >> n >> H;
    vector d(n, vector<LL>(1));
    vector t(n, 0), len(n, 0);

    int l = 0, r = 0;
    for (int i = 0; i < n; i++) {
        int m;
        cin >> t[i] >> m;
        len[i] = m;
        r += max(t[i], len[i]);
        for (int j = 0; j < m; j++) {
            int x;
            cin >> x;
            d[i].pb(x);
        }
        for (int j = 1; j < (int)d[i].size(); j++) {
            d[i][j] += d[i][j - 1];
        }
    }

    LL ans = inf;

    auto chk = [&](int mid) -> bool {
        vector <LL> f(1 << n, inf);

        function <LL(int)> dfs = [&](int S) -> LL {
            if (f[S] != inf) return f[S];

            int tot_time = 0;
            LL damage = 0;
            for (int i = 0; i < n; i++) {
                if (S >> i & 1) {
                    tot_time += t[i];
                }
            }
            for (int i = 0; i < n; i++) {
                if (S >> i & 1 ^ 1) {
                    if (mid - tot_time + 1 <= 0) continue;
                    LL now = d[i][min(len[i], mid - tot_time + 1)];
                    damage = max(damage, now + dfs(S | (1 << i)));
                }
            }
            return f[S] = damage;
        };

        LL damage = dfs(0);
        return damage >= H;
    };

    r = r * 2 + 10;
    while (l < r) {
        int mid = l + r >> 1;
        if (chk(mid)) r = mid;
        else l = mid + 1;
    }

    cout << (chk(r) ? r : -1) << endl;
}

int main () {
    cin.tie(nullptr)->sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int T = 1;
    for (multi_cases && cin >> T; T; T--) {
        A_SOUL_AvA ();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3241ms
memory: 16928kb

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