QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#615291#5453. Mana CollectionDimash8.333333 1919ms90108kbC++233.0kb2024-10-05 18:00:242024-10-05 18:01:42

Judging History

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

  • [2024-10-05 18:01:42]
  • 评测
  • 测评结果:8.333333
  • 用时:1919ms
  • 内存:90108kb
  • [2024-10-05 18:00:24]
  • 提交

answer

#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
const int  N = 22, MOD = (int)1e9 + 7;
const ll inf = 1e18;

int n, m;
ll d[N][N], c[N], dp[(1 << 19) + 1][20], s[(1 << 19) + 1];
void prec() {
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < n; k++) {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    for(int i = 0; i < (1 << n); i++) {
        for(int j = 0; j < n; j++) {
            if((i >> j) & 1) {
                s[i] += c[j];
                if(__builtin_popcount(i) != 1) {
                    dp[i][j] = inf;
                }
            }
        }
    }
}

struct line{
    ll k, b;
    ll get(ll x) {
        return k * x + b;
    }
};
vector<line> st[N];
vector<array<ll, 2>> f[N];


bool check(line x, line y, line z) {
    return (x.b - y.b) * (z.k - y.k) >= (y.b - z.b) * (y.k - x.k);
}
void add(int i, line x) {
    while((int)st[i].size() >= 2 && check(st[i][(int)st[i].size() - 2], st[i].back(), x)) {
        st[i].pop_back();
    }
    st[i].push_back(x);
}
ll get(int i, ll x) {
    ll ret = 0;
    for(auto j:st[i]) {
        ret = max(ret, j.get(x));
    }
    return ret;
}
void test() {
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            d[i][j] = inf;
        }
        d[i][i] = 0;
    }
    for(int i = 1; i <= m; i++) {
        int a, b, t;    
        cin >> a >> b >> t;
        a--;
        b--;
        d[a][b] = t;
    }
    prec();
    for(int i = 0; i < (1 << n); i++) {
        for(int j = 0; j < n; j++) {
            if((i >> j) & 1) {
                for(int k = 0; k < n; k++) {
                    if(!((i >> k) & 1)) {
                        int nv = (i + (1 << k));
                        if(d[j][k] == inf) continue;
                        dp[nv][k] = min(dp[nv][k], dp[i][j] + s[i] * 1ll * d[j][k]);
                    }
                }
            }
        }
    }
    for(int i = 0; i < (1 << n); i++) {
        for(int j = 0; j < n; j++) {
            if((i >> j) & 1) {
                f[j].push_back({s[i], -dp[i][j]});
            }
        }
    }
    for(int i = 0; i < n; i++) {
        sort(f[i].begin(), f[i].end());
        reverse(f[i].begin(), f[i].end());
        for(auto [k, b]:f[i]) {
            add(i, {k, b});
        }
    }
    int q;
    cin >> q;

    while(q--) {
        int t, e;
        cin >> t >> e;
        e--;
        ll res = get(e, t);
        // for(int i = 0; i < (1 << n); i++) {
        //     if((i >> e) & 1) {
        //         res = max(res, s[i] * 1ll * t - dp[i][e]);
        //     }
        // }
        cout << res << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    
    int t = 1; 
    // cin >> t;
    
    while(t--) 
        test();
    return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 4.16667
Accepted
time: 1ms
memory: 5540kb

input:

2 1
1 10
1 2 10
4
5 1
5 2
100 1
100 2

output:

5
50
100
1090

result:

ok 4 number(s): "5 50 100 1090"

Test #2:

score: 4.16667
Accepted
time: 1ms
memory: 5804kb

input:

4 8
50000000 100000000 20000000 70000000
1 2 20
2 1 50
2 3 90
1 3 40
3 1 10
4 1 25
1 4 5
4 3 70
3
8 3
1000000000 1
500000 4

output:

160000000
239999988050000000
119992550000000

result:

ok 3 number(s): "160000000 239999988050000000 119992550000000"

Test #3:

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

input:

10 90
95677166 99413032 90081107 97391055 96848266 92520734 90623124 96509760 95451402 99152599
1 10 94105173
3 9 91922842
5 2 90862613
8 3 94419460
4 7 90084016
6 4 90693719
10 8 97125103
2 1 93286961
5 10 91546334
4 8 92053784
8 5 96537357
3 1 95913083
1 3 95054163
2 8 95986698
7 6 95233705
8 10 9...

output:

11384427252437648
459620067337423078
199246791847496366
217008354297707929
130599674895038497
57548868973614756
41642177065574112
31458291060454024
377619800822577680
75100759913863622
153720059395474154
29907993602057337
54641010427689305
357166153008884667
105734654793291038
8302451008105476
29910...

result:

wrong answer 1st numbers differ - expected: '11703326493772984', found: '11384427252437648'

Test #4:

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

input:

10 90
48104151 45958764 10384927 58976477 4508220 48401738 63414134 56241331 43456656 5364282
4 3 34321182
3 8 6111111
10 3 89336838
7 6 15869517
9 6 45416322
6 8 65416493
8 7 68165563
1 10 17098910
5 7 23144280
10 5 41059929
4 5 83655589
8 2 11141593
10 4 47789741
6 4 15702833
6 5 3119771
9 5 79973...

output:

3076825890335866
35976110096853641
4405889456973981
7188092660650715
2219055044691959
8929454818858671
281310401340040631
16330608648624561
62633383479101386
43456656
1873662209452481
374184651748191311
1253158266813619
456688956670543
32299476475104361
772476708605571
49695253783447186
118051902767...

result:

wrong answer 1st numbers differ - expected: '3586313126541447', found: '3076825890335866'

Test #5:

score: 0
Wrong Answer
time: 35ms
memory: 6000kb

input:

10 87
61275784 16282886 58999609 52155395 53012427 89533414 15431931 35150033 58505854 59445220
9 5 3496028
7 6 17372183
8 1 287847
2 7 19991219
4 5 40820118
4 9 38405375
1 4 52061958
1 3 95765844
9 7 88432897
10 3 62181295
2 4 2070594
6 8 38490628
5 1 74834920
5 2 58054124
5 10 53052912
9 10 799932...

output:

15925470828810113
20178949632622454
8705010100188736
17683529229731121
89156978276985
4422210307309368
6920015312124804
148783617369660
309113940077051823
178911980768416
35871044095338425
4940669033742588
20622524959961725
12251866536344748
2933762607222001
19976040293900907
3059912729948189
389391...

result:

wrong answer 1st numbers differ - expected: '18729278111132298', found: '15925470828810113'

Test #6:

score: 0
Wrong Answer
time: 37ms
memory: 5924kb

input:

10 90
95356560 91592390 93197917 98740065 97680300 92412698 94329246 97243226 90272368 97469569
10 6 99745186
9 3 93877572
4 3 95758698
6 10 91855996
5 1 90121278
5 4 95076290
8 2 99231614
10 3 93399573
4 1 91994993
6 5 94052740
5 2 96068955
2 10 91338395
7 10 91890588
4 7 94880828
1 6 96554961
7 5 ...

output:

157332625069784539
116424917976233252
305333372870864837
30425218460078655
85658661663911532
65786968397086308
1430138781796740
51945241947045071
366637003988093961
15356812520444400
26120838847583602
515435644424449526
16172296984009200
190911996877902121
93213356148577701
241751425557968953
275858...

result:

wrong answer 1st numbers differ - expected: '163280051600495389', found: '157332625069784539'

Test #7:

score: 0
Wrong Answer
time: 36ms
memory: 8032kb

input:

10 89
93795458 90122950 90809309 91512557 99759510 98879743 90406791 91988172 98723686 97265654
3 1 92410620
6 10 787488884
1 7 872243221
5 10 93057933
8 3 90945371
7 4 94869387
1 4 90377187
9 1 92060643
10 8 98532700
9 5 97326866
10 2 98947943
1 6 96415500
10 4 92676865
8 7 92985312
9 6 98444476
1 ...

output:

95240099900334617
19269273838332822
26128229952626609
54575080388138650
62770737426117279
194557262158768776
283247329878870158
134217418244268733
65076603800082364
487594284918169540
95854280819953037
8265311830154500
389778345137195770
423307921353158240
214573488365673249
86365432118163647
400522...

result:

wrong answer 1st numbers differ - expected: '96011873276486328', found: '95240099900334617'

Test #8:

score: 0
Wrong Answer
time: 35ms
memory: 5716kb

input:

10 89
1382293 67193843 93859961 477481 92652257 99885499 50256117 70192761 34119368 16710544
9 10 42167550
5 8 37587488
6 1 39681485
2 6 83885591
2 8 63502599
2 7 96584704
3 2 28849619
1 2 89615158
7 6 49082361
6 7 6114228
6 10 45456432
7 4 87603741
1 8 8377024
5 9 3400067
10 4 42824742
8 1 34659500...

output:

4777622225736047
44321859738905598
34574690056465138
4762296122203660
45105348161861191
90621756903489777
22528595380597965
720752115223263
21727863104712452
32640704467756821
35012500150605
613628626300050
13461926383661340
1107101218941135
1818424411309
1642536302610377
34119368
778135476720094
61...

result:

wrong answer 1st numbers differ - expected: '5212184985750879', found: '4777622225736047'

Test #9:

score: 0
Wrong Answer
time: 28ms
memory: 5656kb

input:

10 90
97766575 91352441 94775266 90513638 95828190 90356289 90495007 98680228 93010243 98543991
1 3 99109059
5 8 90074960
6 5 90055463
6 1 90819495
8 9 98346448
8 5 90223065
10 9 92780029
3 6 90250424
9 1 96050114
7 3 90956675
4 2 92037130
4 7 90691071
2 3 91565269
8 3 94131990
2 9 97006947
4 10 942...

output:

8773129927176957
124894240051522675
20293571075207245
57799179020736481
124894240051522675
60556081726010782
10862861158053582
145143075976992778
94929965026267926
6191082227085588
157184822270992162
74453900660971777
26275490371094290
99884679935428226
116559017896739961
38033766452872566
379603886...

result:

wrong answer 2nd numbers differ - expected: '176141491594572157', found: '124894240051522675'

Test #10:

score: 0
Wrong Answer
time: 361ms
memory: 86776kb

input:

18 306
97592575 5845225 97094410 61652068 60514373 77053365 82408570 65859870 52309184 11075991 79663473 60429988 64440299 88087418 51883591 39638284 31941363 95790465
18 7 12121248
13 6 28252098
14 12 2481192
4 16 54868108
13 15 33001477
7 13 15911113
8 16 47075458
7 14 51352052
9 2 41100503
18 10 ...

output:

56136429870080898
861514584289396
25141077237778179
1419891960310988
4176857381000073
15526453409009261
27820266976384304
5586253246460886
10308680114406012
14245892822521482
851653689252567
23921408316672
488836795657545
32664360938723123
37210360409472317
37104556240044866
6691486767602186
3189400...

result:

wrong answer 1st numbers differ - expected: '56264701460108257', found: '56136429870080898'

Test #11:

score: 0
Wrong Answer
time: 362ms
memory: 86532kb

input:

18 306
54786856 23623482 37443275 34976477 27052191 21997277 93803298 62986079 72289998 36640646 66962609 75940630 20835955 36012773 32492294 69398349 49378951 13097897
7 10 5470000
8 7 53513890
3 15 38460382
7 16 19142503
5 14 45517218
18 17 42648313
8 18 48305235
4 16 41424027
5 12 52928903
5 4 44...

output:

16171535163652334
42290239398382952
60201966145415
27565507275023545
15238903245879619
25585101414434957
392169135242117
15551936813049654
1091286304394253
91405343035120
2929203146383273
33638747872523961
1650268039777448
4437122652272616
18171579684609106
38909974482767497
3512538067116326
1358925...

result:

wrong answer 1st numbers differ - expected: '16448924998323876', found: '16171535163652334'

Test #12:

score: 0
Wrong Answer
time: 371ms
memory: 86284kb

input:

18 303
87437585 22204459 77335222 63373455 24384957 40111770 61538701 65736765 65450807 20008686 60461910 77184085 62951808 75441264 35010255 67513271 41855413 84760939
6 14 45984925
3 6 5610402
8 1 49203830
8 3 53792394
10 8 11629718
1 12 20708032
4 6 14035635
15 18 487975772
3 1 28292662
3 10 2399...

output:

907972841644624
33627416975347019
9304961138747108
669207273505472435
5245027705350078
5719621419425785
5514807239824672
5476559627429734
9090655045132816
929571390607270268
6084803518780038
8252681153633539
6966807973700058
31918102270517703
221430127060560
4937851387326873
42315710136337004
316138...

result:

wrong answer 1st numbers differ - expected: '1107904896715516', found: '907972841644624'

Test #13:

score: 0
Wrong Answer
time: 360ms
memory: 86684kb

input:

18 300
95399651 98514702 95906995 99120696 97373712 99841892 95487998 98629037 97207398 99163728 97816361 94919203 95202846 96133518 98849047 99498436 94447669 96164861
10 8 54922237
1 2 55368382
10 4 54029624
9 8 55267410
14 2 53427574
14 18 54579322
3 9 54230956
2 9 52630731
4 16 53837522
3 7 8372...

output:

109547258785001075
83338744431173509
538773770095058863
298066449679008521
103027116718060962
382751649963480723
299237897434708266
147563614215030527
540451907676804367
8039024919663775
615076168910907184
107928619106714007
5749275490245941
227123052716688151
536386570341528951
260685802735911946
3...

result:

wrong answer 2nd numbers differ - expected: '83350392507237245', found: '83338744431173509'

Test #14:

score: 0
Wrong Answer
time: 356ms
memory: 87580kb

input:

18 306
94983318 99500146 99056770 99199070 96785433 94689368 96603811 97464542 96757856 95575432 97758260 96271537 94822391 98897205 96531324 95046283 95759027 99689250
14 18 54518764
3 8 54402270
16 8 52601874
3 11 52679529
13 6 54902169
1 10 54363631
4 2 55268135
5 6 52963284
16 1 52494958
12 11 5...

output:

233127738488362571
148625200927277906
130975094816032935
27858114387271383
184697020121668737
86521488074704204
175019845343133668
237600261890037779
107448304078733938
23488569223448178
469425665217621752
16336373033430900
476541156783774122
363834619564573502
11152251692616765
313493248739352082
7...

result:

wrong answer 1st numbers differ - expected: '233314656911878890', found: '233127738488362571'

Test #15:

score: 0
Wrong Answer
time: 104ms
memory: 24416kb

input:

16 240
47666600 44327219 49953274 41785108 32073587 24424080 30939819 78762914 90224099 59998405 64133109 48652631 22221281 96356764 38490560 116991
1 2 91993819
1 3 97619874
1 4 89451708
1 5 79740187
1 6 94041352
1 7 78606419
1 8 126429514
1 9 137890699
1 10 107665005
1 11 111799709
1 12 96319231
1...

output:

116995136040717949
21001066478236152
41421659975304540
21271869876085158
22340963348364800
51863311869048372
160366393026101409
198818914813059590
9034911136372200
25784917364776092
145148330282134816
55196847068363042
21204949383407370
34764524818480750
24160213893180800
8601137416790870
9558895562...

result:

wrong answer 1st numbers differ - expected: '212540929497153000', found: '116995136040717949'

Test #16:

score: 0
Wrong Answer
time: 125ms
memory: 24236kb

input:

16 240
42361838 31647618 32114308 8782634 17345648 68132951 88405030 26942819 62741100 66985295 20876520 8437021 27114112 66925976 7183979 94977427
2 15 58174648
8 15 34276605
6 10 58212397
2 13 58804593
13 9 54225029
15 14 33719184
11 13 61087050
9 10 28955627
6 2 10289499
10 2 20518981
13 8 837959...

output:

493210283393155328
14109852994295266
1405008968407591
1910294143498426
1568549936197320
5679258020493830
7390374042888448
109738708259378
101052132975905
4995358193842403
6350505508942574
12563793061107730
4650538786371775
173253576572124
14244327981288574
16084621934430236
11986077817636778
1070602...

result:

wrong answer 2nd numbers differ - expected: '16457452249109400', found: '14109852994295266'

Test #17:

score: 0
Wrong Answer
time: 182ms
memory: 24480kb

input:

16 240
94916675 95328982 94461789 98179130 96410042 95984504 99026406 96722757 98043813 97126519 99521857 99735210 99833885 94048501 93989630 97045699
5 6 61339353
7 11 61447467
16 7 59391553
15 5 61958471
13 2 59603541
13 16 60250166
2 3 61615858
16 3 60312774
14 6 61619256
9 2 61767236
7 12 608785...

output:

689805079643293987
71630339365499072
80281405944246141
33873934416969510
65646034287806393
131029575884676222
18823446167466431
256785647801634124
425301267931667908
6949157325116040
461371852032214319
206865523437266045
368182260189377990
607764836289729979
92287852868132265
673947879062576093
8172...

result:

wrong answer 1st numbers differ - expected: '690101190008603503', found: '689805079643293987'

Test #18:

score: 0
Wrong Answer
time: 317ms
memory: 46220kb

input:

17 269
10989016 28905152 56011456 36383994 32588074 40160206 81943847 29653018 81874689 11531228 28812650 79088847 31042740 89163087 58731031 57356809 5076315
2 4 54972232
1 17 48426734
17 8 7126979
7 2 16376090
10 7 30672058
8 17 55225752
2 6 312152706
4 12 1609956
11 10 44726737
7 6 16333848
17 9 ...

output:

4533512996869882
314963516039757
4918395190185622
234300416313239
7000734063321345
2276718506200816
1870153432675835
1630330782465219
7359945871812014
55608097708270168
4378522523312984
17393033467271332
32715949624967947
54808409846460
65065689951230
55453810033434322
319921138404424
2850473436688
...

result:

wrong answer 1st numbers differ - expected: '5581509823816012', found: '4533512996869882'

Test #19:

score: 0
Wrong Answer
time: 512ms
memory: 44796kb

input:

17 241
20878633 21727433 30788417 1919362 24415556 26527489 14285320 3437901 23517959 28616698 11361867 15220890 21496568 20470194 31073215 5981317 11566475
1 2 42606066
1 3 98682648
1 4 22797995
1 5 45294189
1 6 47406122
1 7 35163953
1 8 24316534
1 9 44396592
1 10 49495331
1 11 32240500
1 12 360995...

output:

108874984881706836
39998804750741760
7180506294956247
47159652242513910
128215794738320312
4126981818415894
17898528979168320
133380710676095343
74727691192326101
131645427536605922
104948693701281264
706440289641834
154697776830457968
6766516501693516
103373859593846186
44351200858518540
1844453686...

result:

wrong answer 2nd numbers differ - expected: '39998804782948735', found: '39998804750741760'

Test #20:

score: 0
Wrong Answer
time: 767ms
memory: 45524kb

input:

17 241
26896510 11416857 23632920 22663714 10426416 1449988 6534437 21431904 6332558 5350871 7478640 7144884 1667707 31989074 24328111 14606283 16379885
1 2 38313367
1 3 50529430
1 4 89019020
1 5 37322926
1 6 28346498
1 7 33430947
1 8 48328414
1 9 33229068
1 10 32247381
1 11 48235649
1 12 34041394
1...

output:

32774392309898748
44979916726686534
78532755901649921
69880405813821389
100757975694356954
32736929841264894
10044394824662794
20540406091018050
47761393742370
72716173770109619
176042587180466333
130113285701048912
107065318334030444
103104460019043248
173458077436724618
1656676262886946
1150030928...

result:

wrong answer 1st numbers differ - expected: '32779028068219037', found: '32774392309898748'

Test #21:

score: 0
Wrong Answer
time: 760ms
memory: 87352kb

input:

18 273
5856998 26869251 1761061 23339731 6696975 12073312 26103914 9146585 14284107 2290011 33149581 6690606 1938529 2611081 4180578 15507572 12766646 8196720
1 2 32726249
1 3 7618059
1 4 29196729
1 5 12553973
1 6 17930310
1 7 31960912
1 8 15003583
1 9 20141105
1 10 8147009
1 12 12547604
1 13 779552...

output:

59668433821480730
11829429544515808
94313798310579388
39465698212066916
3285928984920873
93985077914518126
92458668039991
42234859869227868
145833098207262986
169278502787400280
141749264332210056
8905419934130360
166285047110364266
30697972443940536
92813594329636480
13349305758991590
4812110771433...

result:

wrong answer 2nd numbers differ - expected: '11829620092917720', found: '11829429544515808'

Test #22:

score: 0
Wrong Answer
time: 1587ms
memory: 88144kb

input:

18 273
18655021 10530209 4072104 27397860 1799797 31844906 10224838 22363503 8387103 25160565 867464 18587455 28492008 3583506 7250222 12947265 13542506 15353338
1 2 29185230
1 3 22727125
1 4 46052881
1 5 20454818
1 6 50499927
1 8 41018524
1 9 44747129
1 10 43815586
1 11 28438355
1 12 37242476
1 13 ...

output:

191914217942017249
177821186291840089
159567710118372739
63027783847588969
2732703036051690
178142648642986339
6690081437120483
50835884526345699
146778571533991969
89494581427392
14888572854202581
5461352323429621
40061520484213176
12018440634362280
55503813555332625
15564070375174728
1378183319530...

result:

wrong answer 4th numbers differ - expected: '63405979674965583', found: '63027783847588969'

Test #23:

score: 0
Wrong Answer
time: 1919ms
memory: 90108kb

input:

18 273
18425031 23650394 24880771 20922906 26575943 17784399 1257646 4304768 2028569 32225860 3162758 23575563 21688821 6218252 30502483 720206 33244851 27314277
1 2 43683269
1 3 61643789
1 4 75113213
1 5 58792271
1 6 52052510
1 7 28904939
1 8 22817172
1 9 26122275
1 11 24226530
1 12 77523542
1 13 6...

output:

1128051550016138
62660333585940278
38630507855079688
27245033067916148
98433582110090573
113095555313189897
25219794294120710
201786421030430027
281590654555228
114901795935593639
206619347600715407
197117228100400439
3474636620252742
8391413876807052
3279654175784833
88500335320334981
1485285715235...

result:

wrong answer 1st numbers differ - expected: '1138546366805558', found: '1128051550016138'

Test #24:

score: 0
Wrong Answer
time: 1259ms
memory: 87160kb

input:

18 273
26613501 27441209 12794702 13658897 32546072 2607103 21792275 12508707 8092259 2836952 26658654 15275240 16574454 31623641 1150608 21764569 30050392 12599166
1 2 54054710
1 3 39408203
1 4 40272398
1 5 59159573
1 6 29220604
1 7 48405776
1 9 34705760
1 10 29450453
1 11 53272155
1 12 41888741
1 ...

output:

2225420775516288
48604169432182440
491502509968288
2482793597743550
1260109285138680
195656962515960415
8732146742783067
95872913113293391
82418460650660499
180808046186578708
162632332510855528
106925249733973735
218492366742382045
34505896623851608
86451305617213591
59859692043386440
3124458064959...

result:

wrong answer 1st numbers differ - expected: '2709709040134800', found: '2225420775516288'