QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187143#6660. 택시 여행Cyanmond0 1050ms157204kbC++175.9kb2023-09-24 14:56:142023-09-24 14:56:14

Judging History

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

  • [2023-09-24 14:56:14]
  • 评测
  • 测评结果:0
  • 用时:1050ms
  • 内存:157204kb
  • [2023-09-24 14:56:14]
  • 提交

answer

#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= l; --i)
#define ALL(x) (x).begin(), (x).end()

using i64 = long long;

struct Edge {
    int to;
    i64 cost;
};

struct CHTMonotone {
    using P = pair<i64, i64>;
    deque<P> deq;

    i64 eval(const P &line, i64 x) {
        return line.first * x + line.second;
    }

    bool check(const P &l1, const P &l2, const P &l3) {
        return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);
    }

    // add decreasing
    // query decreasing
    void add(const P &line) {
        if (deq.empty()) deq.push_front(line);
        else {
            if (deq.front().first == line.first) {
                if (deq.front().second > line.second) {
                    deq.pop_front();
                } else {
                    return;
                }
            }
            while (deq.size() >= 2 and check(line, deq[0], deq[1])) deq.pop_front();
            deq.push_front(line);
        }
    }

    i64 query(i64 x) {
        if (deq.empty()) return 1ll << 60;
        i64 mi = 1ll << 60;
        for (const auto &line : deq) mi = min(mi, eval(line, x));
        return mi;
    }
};

std::vector<long long> travel(std::vector<long long> A,
        std::vector<int> B, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    const int N = (int)A.size(), M = (int)U.size();
    vector<vector<Edge>> tree(N);
    rep(i, 0, M) {
        tree[U[i]].push_back({V[i], W[i]});
        tree[V[i]].push_back({U[i], W[i]});
    }

    vector<int> par(N);
    vector<i64> depth(N);
    vector<int> dep1(N);
    auto dfs = [&](auto &&self, const int v, const int p, i64 d, int d1) -> void {
        par[v] = p;
        depth[v] = d;
        dep1[v] = d1;
        for (const auto &[t, c] : tree[v]) {
            if (t == p) continue;
            self(self, t, v, d + c, d1 + 1);
        }
    };
    dfs(dfs, 0, -1, 0, 0);

    vector<vector<int>> table(20, vector<int>(N));
    table[0] = par;
    rep(rank, 1, 20) {
        rep(i, 0, N) {
            if (table[rank - 1][i] == -1) table[rank][i] = -1;
            else table[rank][i] = table[rank - 1][table[rank - 1][i]];
        }
    }

    auto calcLCA = [&](int u, int v) {
        if (dep1[u] > dep1[v]) swap(u, v);
        per(rank, 0, 20) {
            const int t = table[rank][v];
            if (t != -1 and dep1[t] >= dep1[u]) {
                v = t;
            }
        }
        if (u == v) return u;
        per(rank, 0, 20) {
            const int a = table[rank][u], b = table[rank][v];
            if (a == b) continue;
            u = a, v = b;
        }
        return par[u];
    };

    auto calcDist = [&](int a, int b) {
        const auto lca = calcLCA(a, b);
        return depth[a] + depth[b] - 2 * depth[lca];
    };

    vector<CHTMonotone> chts(N);
    vector<vector<int>> roots(N);

    vector<bool> isAvailable(N, true);
    vector<int> subSize(N);

    auto centDec = [&](auto &&self, const int root) -> void {
        auto dfs1 = [&](auto &&self, const int v, const int p) -> int {
            subSize[v] = 1;
            for (const auto &[t, c] : tree[v]) {
                if (t == p) continue;
                if (not isAvailable[t]) continue;
                subSize[v] += self(self, t, v);
            }
            return subSize[v];
        };
        dfs1(dfs1, root, -1);

        int centroid = -1, sSum = subSize[root];
        auto dfs2 = [&](auto &&self, const int v, const int p) -> void {
            bool isCen = true;
            for (const auto &[t, c] : tree[v]) {
                if (t == p) continue;
                if (not isAvailable[t]) continue;
                self(self, t, v);
                if (subSize[t] > sSum / 2) isCen = false;
            }
            if (sSum - subSize[v] > sSum / 2) isCen = false;
            if (isCen) centroid = v;
        };
        dfs2(dfs2, root, -1);

        auto dfs3 = [&](auto &&self, const int v, const int p) -> void {
            roots[v].push_back(centroid);
            for (const auto &[t, c] : tree[v]) {
                if (t == p) continue;
                if (not isAvailable[t]) continue;
                self(self, t, v);
            }
        };
        dfs3(dfs3, root, root);

        for (const auto &[t, c] : tree[centroid]) {
            if (not isAvailable[t]) continue;
            subSize[t] = -centroid - 1;
            isAvailable[t] = false;
        }
        isAvailable[centroid] = false;

        for (const auto &[t, c] : tree[centroid]) {
            if (subSize[t] == -centroid - 1) {
                subSize[t] = 0;
                isAvailable[t] = true;
            }
            if (not isAvailable[t]) continue;
            self(self, t);
            isAvailable[t] = false;
        }
    };
    centDec(centDec, 0);

    vector<pair<i64, int>> vs;
    rep(i, 0, N) vs.push_back({B[i], i});
    sort(ALL(vs), greater());
    vector<i64> dist(N, 1ll << 60);
    dist[0] = 0;
    for (const auto &[b, i] : vs) {
        for (const auto r : roots[i]) {
            i64 d = calcDist(i, r);
            i64 cost = chts[r].query(d);
            dist[i] = min(dist[i], cost);
        }

        if (dist[i] == (1ll << 60)) continue;
        const auto baseCost = dist[i] + A[i];
        for (const auto r : roots[i]) {
            i64 d = calcDist(i, r);
            i64 cost = d * B[i];
            chts[r].add({B[i], baseCost + cost});
        }
    }

    vector<i64> ans(N - 1);
    rep(i, 1, N) {
        for (const auto r : roots[i]) {
            i64 d = calcDist(i, r);
            i64 cost = chts[r].query(d);
            dist[i] = min(dist[i], cost);
        }
        ans[i - 1] = dist[i];
    }
    return ans;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 0ms
memory: 3808kb

input:

2
684124582850 713748627948
74361 256955
0 1 661088

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
733283747618
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 3 lines

Test #2:

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

input:

3
251115773325 363097865287 358609487841
826785 213106 914768
0 1 851938
2 0 231697

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
955485332655
442679377470
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 4 lines

Test #3:

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

input:

3
489998888627 318672977903 70353752652
258347 458793 258657
2 1 156120
0 2 524840

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
665922861747
625589728107
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 4 lines

Test #4:

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

input:

3
737471938521 315388610250 818943569900
726908 666797 564862
0 1 460302
0 2 785280

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1072069144737
1308298252761
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 4 lines

Test #5:

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

input:

4
201836820267 208957719162 992553400562 566050337171
243994 65303 590123 936951
1 0 259719
0 3 860376
3 2 513584

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
265206697953
537074816507
411763402011
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 5 lines

Test #6:

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

input:

4
440719935569 160237864481 704297665373 767778991240
451998 371509 46564 828427
1 0 861960
1 3 830699
2 3 185693

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
830324131649
1289731282865
1205798418251
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 5 lines

Test #7:

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

input:

5
148262899914 9382086008 622202345986 443806901161 213829280326
178155 503016 333953 572340 461148
0 3 453941
3 2 84057
4 0 171136
3 1 598794

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
335812903839
244109933604
229134758769
178751633994
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 6 lines

Test #8:

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

input:

5
391440982512 969252165920 333946610796 649830522527 902812044171
522045 996458 225429 545971 667483
0 1 701500
0 4 514779
2 1 435377
3 0 919439

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
757655550012
984941935977
871429515267
660178785567
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 6 lines

Test #9:

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

input:

17
315015458526 65513576283 829720084774 654640079244 561177336848 463903843105 496216524512 837433489064 92734412345 807145138979 250511786518 915329126804 373916658654 78276842047 121976569238 432447179015 519384539551
696133 642473 231377 987220 589587 337763 790202 785083 249580 108311 73808 892...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
430639669161
417840567823
403532946274
499079112962
498466070651
495984520010
499402357184
501387707132
498265325456
501233852966
474661031682
494612046266
411867746683
497598865088
499819422548
496976423075
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 18 lines

Test #10:

score: -7
Wrong Answer
time: 0ms
memory: 3852kb

input:

20
764145449871 794297102632 450082553736 427358261877 587251097098 98567356955 15910789509 321286084089 25839798358 969219436118 975479420690 937908953492 410498404545 180209954689 302999489632 849828117651 171771046425 800442975277 295169929534 146003957886
828538 724406 733109 79844 665172 652593...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1579695288183
871900130923
1468189815605
1377891601675
924349900475
1090260492285
1115568185495
864751505059
1253658128341
824076089025
1470641459547
1666279994797
1962895770259
1436267903541
1478403270966
1303312410681
1568823212547
1135576549657
1412080059777...

result:

wrong answer 2nd lines differ - expected: '1384833390877', found: '1579695288183'

Subtask #2:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 1050ms
memory: 150300kb

input:

100000
746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1148030742334
1636760433058
2131282232650
2408842387198
2672707119337
3030852161530
3540051650386
3642760318287
3596166938027
3173036690606
3584624301317
3889605432099
3677853106627
3328434230236
3934909414812
3965028927015
3981082408635
3982815071490
399337774...

result:

wrong answer 5th lines differ - expected: '2353514637869', found: '2408842387198'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #69:

score: 0
Wrong Answer
time: 131ms
memory: 115488kb

input:

100000
15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
16817058
...

result:

wrong answer 2nd lines differ - expected: '16705757', found: '16817058'

Subtask #5:

score: 0
Wrong Answer

Test #94:

score: 29
Accepted
time: 155ms
memory: 151364kb

input:

99281
551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
598598746654
5...

result:

ok 99282 lines

Test #95:

score: 0
Accepted
time: 231ms
memory: 153740kb

input:

100000
762048253398 544847923340 274220772253 709492519024 93107863549 990677171512 878434244170 777350365410 575870270443 928311965336 349432073756 948390047110 470116186153 495432094032 154258868766 719518553291 580490378718 661863092617 453262793865 191963964294 783054160061 953488248260 99347544...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
7...

result:

ok 100001 lines

Test #96:

score: 0
Accepted
time: 387ms
memory: 147304kb

input:

94281
131658172659 39811340435 707706551378 488270943344 316094085836 187344969354 859815132521 257455926058 398461451565 636824600504 968337263051 657378201148 381422070176 704193397218 215057852195 143696981366 245020143023 544889243460 19853724068 381481133078 270430609102 661194702920 9327187294...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
513000148750
5...

result:

ok 94282 lines

Test #97:

score: 0
Accepted
time: 638ms
memory: 153888kb

input:

98013
219274952148 967847968840 993514312942 249215975388 377408063086 409277664478 513688960578 870781013811 5313297905 381786485971 932846528432 355907313844 568982393234 615505455703 556586556337 580222086746 513159753737 447726612888 849878699364 872433100635 459323693660 591180592643 9928561494...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
397148182990
3...

result:

ok 98014 lines

Test #98:

score: 0
Accepted
time: 882ms
memory: 157204kb

input:

100000
793084247557 856407004352 124019471672 758580217324 391555277659 748332370727 824874943785 454763878407 172204390651 200693040566 241971294452 420325832639 276303819033 490288760803 518648078771 428578774460 552156115324 270613111346 564717918818 914239531441 363337438048 359070665547 4058804...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
1347236750935
134723675...

result:

ok 100001 lines

Test #99:

score: 0
Accepted
time: 151ms
memory: 152944kb

input:

100000
186878865231 744364257898 407647146449 178229661742 142659258467 867497410431 566102005411 743741769325 966116499644 374901320569 460953729268 166466122244 599772360298 778326103398 923306353276 541041861259 456336739387 460166266166 277100384431 124520154825 91585321170 808947541069 49305171...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
199304498331
1...

result:

ok 100001 lines

Test #100:

score: 0
Accepted
time: 215ms
memory: 154332kb

input:

100000
701868643554 195683029255 191726673386 60711384096 246001015103 235534486089 867356428487 679339700226 266886499198 165357218261 892542762609 49935133853 78861964822 648163497576 458431664651 259806246005 944174571815 556122544299 640157239681 239448194098 270814892412 832337696089 1764039054...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
786865661638
7...

result:

ok 100001 lines

Test #101:

score: 0
Accepted
time: 416ms
memory: 156232kb

input:

100000
438739740535 795928502119 872639081700 294554691174 226473457726 440783927287 150198126950 915922926283 516380773321 487345449103 452763239700 807838622400 226343342171 740475572228 441100842060 488895978441 476807788781 262972018901 384528067019 387913043837 839407743741 462422811237 7784206...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
865668346868
8...

result:

ok 100001 lines

Test #102:

score: -29
Wrong Answer
time: 649ms
memory: 156988kb

input:

100000
694640698205 388240595320 449732757362 105097389837 586358675392 161335658819 425877820487 740670399542 410740826602 978399832816 430048583471 246136844716 701889327015 378563563646 252509017658 388896850779 573768686022 926987324089 60052463883 832676326751 23069584465 214255472478 621178722...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
6169867417128
616986741...

result:

wrong answer 2nd lines differ - expected: '4111303149419', found: '6169867417128'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%