QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142259#4561. Catfish FarmQwerty123226 131ms64588kbC++203.4kb2023-08-18 20:49:112023-08-18 20:49:11

Judging History

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

  • [2023-08-18 20:49:11]
  • 评测
  • 测评结果:26
  • 用时:131ms
  • 内存:64588kb
  • [2023-08-18 20:49:11]
  • 提交

answer

#include "fish.h"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <vector>

long long max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    std::vector<std::vector<std::pair<int, int>>> input(n);
    for (int i = 0; i < m; i++) {
        input[X[i]].push_back({Y[i], W[i]});
    }

    std::vector<std::vector<int>> bd(n);
    std::vector<std::vector<int64_t>> prf(n);
    std::vector<std::vector<int64_t>> prf2(n);

    auto lb = [&](int i, int val) {
        int it = std::lower_bound(input[i].begin(), input[i].end(), std::pair<int, int>{val, -1}) - input[i].begin();
        return it;
    };

    for (int i = 0; i < n; i++) {
        std::sort(input[i].begin(), input[i].end());

        bd[i].resize(input[i].size() + 1);
        for (int j = 0; j < input[i].size(); j++) {
            bd[i][j] = input[i][j].first;
        }
        bd[i].back() = n + 1;

        prf[i].resize(input[i].size() + 1);
        for (int j = 0; j < input[i].size(); j++) {
            prf[i][j + 1] = prf[i][j] + input[i][j].second;
        }
    }
    for (int i = 0; i < n - 1; i++) {
        prf2[i].resize(input[i].size() + 1);
        for (int j = 0; j <= input[i].size(); j++) {
            int it = lb(i + 1, bd[i][j]);
            prf2[i][j] = prf[i + 1][it];
        }
    }
    if (input[0].size() + input[1].size() == m) {
        return std::max(prf[0].back(), prf[1].back());
    }

    std::vector<std::vector<std::vector<int64_t>>> dp(n - 1);

    for (int i = 0; i < n - 1; i++) {
        dp[i].assign(bd[i].size(), std::vector<int64_t>(bd[i + 1].size(), 0));
    }
    for (int a = 0; a < bd[0].size(); a++) {
        for (int b = 0; b < bd[1].size(); b++) {
            if (bd[0][a] <= bd[1][b]) {
                int id = lb(0, bd[1][b]);
                dp[0][a][b] = prf[0][id] - prf[0][a];
            } else {
                int id = lb(1, bd[0][a]);
                dp[0][a][b] = prf[1][id] - prf[1][b];
            }
        }
    }

    auto get_cum = [&](int i, int l, int r) {
        int64_t res = prf[i][lb(i, r)] - prf[i][lb(i, l)];
        return res;
    };

    auto get = [&](int i, int a, int b, int c) -> int64_t {
        int x = bd[i][a], y = bd[i + 1][b], z = bd[i + 2][c];
        if (x > y && y < z) {
            if (b > 0) {
                return -1e18;
            } else {
                if (x >= z) {
                    return 0;
                } else {
                    return get_cum(i + 1, x, z);
                }
            }
        }
        if (y >= z) {
            return get_cum(i + 2, z, y);
        } else {
            return get_cum(i + 1, y, z);
        }
        assert(false);
    };
    for (int i = 0; i + 2 < n; i++) {
        for (int a = 0; a < bd[i].size(); a++) {
            for (int b = 0; b < bd[i + 1].size(); b++) {
                int64_t val = dp[i][a][b];
                for (int c = 0; c < bd[i + 2].size(); c++) {
                    int64_t dlt = get(i, a, b, c);
                    // dlt = get(i, a, b, c) - get(i, a, b, 0);
                    dp[i + 1][b][c] = std::max(dp[i + 1][b][c], val + dlt);
                }
            }
        }
    }

    int64_t res = 0;
    for (int a = 0; a < bd[n - 2].size(); a++) {
        for (int b = 0; b < bd[n - 1].size(); b++) {
            res = std::max(res, dp[n - 2][a][b]);
        }
    }

    return res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 25ms
memory: 24040kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
90000 80699
0 10792 55091480
0 36762 389250726
0 79267 706445371
0 76952 290301137
0 13444 69711795
0 68980 66221400
0 1695 703252611
0 36628 632571604
0 87676 264578012
0 79496 397448339
0 57929 447544332
0 35453 355374818
0 62449 686423696
0 45614 667165709...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
40313272768926

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 42ms
memory: 27104kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 100000
0 64777 995289349
0 71596 893436841
0 577 789941184
0 74238 421759180
0 93045 833843112
0 17349 236016162
0 70194 646518626
0 59769 662584325
0 45550 706340730
0 8007 454213805
0 5460 328535742
0 47262 672607739
0 91960 166922115
0 26216 5441740...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
49915093555295

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 13ms
memory: 21768kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
0 0 10082010

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
10082010

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 6ms
memory: 21796kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
0 99999 19122012

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
19122012

result:

ok 3 lines

Test #5:

score: 0
Accepted
time: 128ms
memory: 64588kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 300000
94880 38243 268662731
31482 11260 116303310
31482 29385 147398833
85804 78816 165663896
85804 50892 232441179
85804 52149 500231552
31482 15077 912836767
94880 13332 204098181
85804 4048 862989578
31482 94135 432330909
85804 30398 552396632
3702...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
149814460735479

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 131ms
memory: 64008kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 300000
66138 12864 1000000000
3750 4109 1000000000
42566 70555 1000000000
33020 72709 1000000000
57804 39219 1000000000
28208 65932 1000000000
13384 22179 1000000000
69976 69860 1000000000
82704 18635 1000000000
74094 31581 1000000000
95460 25871 10000...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
300000000000000

result:

ok 3 lines

Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 1ms
memory: 3656kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
3 2
0 0 1
1 1 1

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
1

result:

wrong answer 3rd lines differ - expected: '2', found: '1'

Subtask #3:

score: 9
Accepted

Test #20:

score: 9
Accepted
time: 5ms
memory: 21768kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
0 0 10082010

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
10082010

result:

ok 3 lines

Test #21:

score: 0
Accepted
time: 24ms
memory: 30516kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
99999 0 882019

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
882019

result:

ok 3 lines

Test #22:

score: 0
Accepted
time: 48ms
memory: 33996kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
90000 53444
40538 0 933021958
22736 0 403565340
52395 0 535014365
46488 0 818102149
19082 0 825246110
7712 0 581240932
30019 0 143288209
16519 0 206714026
8855 0 737518859
44939 0 63482743
40524 0 963968043
2663 0 953447256
25511 0 762455895
10794 0 880225092...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
21261825233649

result:

ok 3 lines

Test #23:

score: 0
Accepted
time: 28ms
memory: 34784kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 35893
58578 0 304141028
55753 0 423438149
28242 0 9158978
26888 0 284963184
54273 0 494234963
29697 0 240842358
86194 0 789279485
58100 0 572200683
57232 0 355330259
21029 0 261781158
20244 0 594911163
84269 0 452539910
35836 0 228436540
86304 0 785924...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
14486631352875

result:

ok 3 lines

Test #24:

score: 0
Accepted
time: 56ms
memory: 42240kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 100000
79988 0 40146450
9642 0 4878540
15808 0 7990718
87998 0 44144800
50 0 28601
87736 0 44009424
1293 0 663798
5837 0 2957384
63202 0 31702174
47501 0 23852124
73162 0 36720321
22116 0 11144107
10533 0 5323103
11339 0 5737527
94001 0 47121962
57059 ...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
1673106170551

result:

ok 3 lines

Test #25:

score: 0
Accepted
time: 46ms
memory: 42140kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 100000
29663 0 1
8831 0 1
36979 0 1
18031 0 1
58035 0 1
17126 0 1
39877 0 1
65204 0 1
95787 0 1
3456 0 1
70567 0 1
32636 0 1
25925 0 1
28249 0 1
44082 0 1
96342 0 1
85086 0 1
34386 0 1
14480 0 1
76553 0 1
52077 0 1
9592 0 1
23079 0 1
40176 0 1
12131 0 ...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
141909

result:

ok 3 lines

Test #26:

score: 0
Accepted
time: 64ms
memory: 42180kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 100000
83585 0 2094163
24287 0 2036215
24300 0 2033375
19914 0 2054613
21378 0 2041083
21499 0 2045341
90833 0 2102645
61879 0 2063456
1760 0 2002021
88192 0 2110989
53350 0 2053627
16287 0 2051126
65429 0 2060736
51431 0 2072545
77128 0 2074487
42574 ...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
136990846207

result:

ok 3 lines

Test #27:

score: 0
Accepted
time: 64ms
memory: 42116kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 100000
85230 0 4609010
60078 0 12007449
43791 0 3942515
1997 0 2998622
56562 0 10337802
20938 0 11560354
76302 0 3874165
47495 0 5809667
11746 0 7920761
33327 0 5406979
78092 0 2965837
99383 0 11744076
52546 0 8319876
51870 0 7985523
71948 0 6035731
86...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
469063835000

result:

ok 3 lines

Subtask #4:

score: 0
Wrong Answer

Test #28:

score: 14
Accepted
time: 1ms
memory: 3704kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
4 3
2 2 1
0 0 1
1 1 1

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
3

result:

ok 3 lines

Test #29:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
8 7
5 5 1
4 4 1
6 6 1
3 3 1
0 0 1
2 2 1
1 1 1

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
7

result:

ok 3 lines

Test #30:

score: -14
Wrong Answer
time: 1ms
memory: 3700kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
3 2
0 0 1
1 1 1

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
1

result:

wrong answer 3rd lines differ - expected: '2', found: '1'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 14
Accepted

Test #60:

score: 14
Accepted
time: 57ms
memory: 42108kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 99999
31026 31026 1
42940 42940 1
69303 69303 1
90350 90350 1
77507 77507 1
87126 87126 1
17988 17988 1
5146 5146 1
63023 63023 1
27776 27776 1
6136 6136 1
82557 82557 1
24904 24904 1
21667 21667 1
67271 67271 1
80294 80294 1
81145 81145 1
47144 47144 ...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
99999

result:

ok 3 lines

Test #61:

score: 0
Accepted
time: 36ms
memory: 26440kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
50000 100000
43737 0 616909786
28149 1 83561192
31215 0 81425452
11831 1 127789871
33975 1 294422160
44409 1 920754334
44149 1 547214118
23078 0 749134931
39070 1 425147230
39398 1 49764337
49388 0 1922565
13827 0 24394607
45462 0 276157952
30584 0 435992379
...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
36454348383152

result:

ok 3 lines

Test #62:

score: 0
Accepted
time: 83ms
memory: 49436kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 200000
74413 0 331848521
65625 1 270985578
74834 1 254858924
64748 0 225446772
49477 1 805769691
51151 0 936768358
3414 0 489367009
16978 1 568800724
73971 1 362063327
69520 0 167769953
74767 0 685485032
98265 0 800000672
37113 0 607119114
76712 0 7360...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
72889508713304

result:

ok 3 lines

Test #63:

score: 0
Accepted
time: 20ms
memory: 30532kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
99999 0 882019

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
882019

result:

ok 3 lines

Test #64:

score: 0
Accepted
time: 27ms
memory: 30536kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 1
99999 99999 1062016

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
1062016

result:

ok 3 lines

Test #65:

score: 0
Accepted
time: 60ms
memory: 40708kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 99714
95877 95661 904971232
48936 51182 87613544
99510 69524 166560840
69063 54711 527961593
44663 66079 840368080
48858 31915 855482971
48792 25347 551893652
3707 58511 133271545
54098 19896 960800491
99183 25598 251063376
32001 95465 62448024
61669 1...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
45561826463480

result:

ok 3 lines

Test #66:

score: 0
Accepted
time: 97ms
memory: 49268kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 200000
42723 5 613400260
58966 2 74293186
85675 5 726517941
55191 2 908099198
80402 5 870990015
75112 2 753630703
89766 2 744115390
61562 3 272169768
20221 3 534855944
55871 1 290708263
7142 2 528459486
73958 2 426196098
63523 6 834100236
55657 3 84532...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
77772396150817

result:

ok 3 lines

Test #67:

score: 0
Accepted
time: 98ms
memory: 49400kb

input:

f785163bfcb92ce6ac387bba5d2f29a0e0f37f19
100000 200000
60643 658 631445964
2961 2963 687789209
87494 2489 784136198
29846 148 831058813
64552 4567 700351843
7992 2006 222736484
75778 4206 149600820
41911 1920 169469933
68695 1291 755002158
79131 854 717849671
30019 26 141467206
17779 2216 918100479
...

output:

938f2698235a9ff1d1d91e23381b68bec7bed102
OK
77992411858808

result:

ok 3 lines

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%