QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#320661#8214. Huge Oil Platformucup-team197#WA 7515ms4288kbC++204.5kb2024-02-03 19:42:082024-02-03 19:42:08

Judging History

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

  • [2024-02-03 19:42:08]
  • 评测
  • 测评结果:WA
  • 用时:7515ms
  • 内存:4288kb
  • [2024-02-03 19:42:08]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <utility>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;
typedef double ld;

struct Point{
    ll x, y, w;

    ll dot(Point p) const {return x * p.x + y * p.y;}
    ll cross(Point p) const {return x * p.y - y * p.x;}
};

const int N = 400 + 3;
#define all(x) (x).begin(), (x).end()

int n;
Point p[N];
ll w[N];

vector<ld> st_ys;

struct SegmentTree{
    struct Node{
        ld sum_w, mx;
        ld best_l, best_r;

        Node(){
            sum_w = mx = best_l = best_r = 0;
        }

        friend Node merge(const Node &l, const Node &r, int idx_l, int idx_r){
            int mid = (idx_l + idx_r) / 2;
            Node ret;
            ret.sum_w = l.sum_w + r.sum_w;
            ret.best_l = max(l.best_l, l.sum_w - 2 * (st_ys[mid + 1] - st_ys[idx_l]) + r.best_l);
            ret.best_r = max(r.best_r, r.sum_w - 2 * (st_ys[idx_r] - st_ys[mid]) + l.best_r);
            ret.mx = max(l.mx, r.mx);
            ret.mx = max({ret.mx, ret.best_l, ret.best_r, l.best_r + r.best_l - 2 * (st_ys[mid + 1] - st_ys[mid])});
            return ret;
        }
    } nd[4 * N];

    void init(int i = 0, int l = 0, int r = (int)st_ys.size() - 1){
        if(l == r){
            nd[i] = Node();
            return;
        }

        int mid = (l + r) >> 1;
        init(2 * i + 1, l, mid);
        init(2 * i + 2, mid + 1, r);
        nd[i] = merge(nd[2 * i + 1], nd[2 * i + 2], l, r);
    }

    void update(int idx, ll w, int i = 0, int l = 0, int r = (int)st_ys.size() - 1){
        if(idx < l || r < idx) return;
        if(l == r){
            nd[i].sum_w += w;
            nd[i].best_l = nd[i].best_r = nd[i].mx = nd[i].sum_w;
            return;
        }

        int mid = (l + r) >> 1;
        update(idx, w, 2 * i + 1, l, mid);
        update(idx, w, 2 * i + 2, mid + 1, r);
        nd[i] = merge(nd[2 * i + 1], nd[2 * i + 2], l, r);
    }

    ld query(int i = 0, int l = 0, int r = (int)st_ys.size() - 1){
        return nd[i].mx;
    }
} st;

ld solve2(vector<ll> &ys, vector<Point> &new_p, ll mid_x, ld div){
    st_ys.resize(ys.size());
    for(int i = 0; i < ys.size(); ++i){
        st_ys[i] = ys[i] / div;
    }
    st.init();

    ld ans = 0;
    for(int i = 0; i < new_p.size(); ++i){
        st.update(lower_bound(all(ys), new_p[i].y) - ys.begin(), new_p[i].w);
        if(i == (int)new_p.size() - 1 || new_p[i].x != new_p[i + 1].x){
            ld cand = -2 * (new_p[i].x - mid_x) / div;
            cand += st.query();
            ans = max(ans, cand);
        } 
    }
    return ans;
}

ld solve(vector<ll> &xs, vector<ll> &ys, vector<Point> &new_p, ll mid_x, ld div){
    sort(all(new_p), [&](auto l, auto r){
        return l.x < r.x;
    });

    vector<Point> left_p, right_p;
    for(int i = 0; i < new_p.size(); ++i){
        if(new_p[i].x >= mid_x){
            right_p.push_back(new_p[i]);
        }
    }
    for(int i = (int)new_p.size() - 1; i >= 0; --i){
        if(new_p[i].x <= mid_x){
            left_p.push_back(Point{-new_p[i].x, new_p[i].y, new_p[i].w});
        }
    }

    return max(solve2(ys, left_p, -mid_x, div), solve2(ys, right_p, mid_x, div));
}

clock_t timer = clock();

bool time_left(){
    return (((float)clock() - (float)timer) / (float)CLOCKS_PER_SEC) <= 7.5;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    ld ans = 0;
    for(int i = 0; i < n; ++i){
        cin >> p[i].x >> p[i].y >> p[i].w;
        ans = max(ans, (ld)p[i].w);
    }

    for(int i = 0; i < n && time_left(); ++i){
        for(int j = i + 1; j < n; ++j){
            vector<Point> new_p;
            Point diff{p[j].x - p[i].x, p[j].y - p[i].y, 0};
            for(int k = 0; k < n; ++k){
                new_p.push_back(Point{p[k].cross(diff), p[k].dot(diff), p[k].w});
            }

            ll mid_x = new_p[i].x;

            vector<ll> xs, ys;
            for(int k = 0; k < n; ++k){
                xs.push_back(new_p[k].x);
                ys.push_back(new_p[k].y);
            }
            sort(all(xs));
            xs.resize(unique(all(xs)) - xs.begin());
            sort(all(ys));
            ys.resize(unique(all(ys)) - ys.begin());


            ld div = sqrt((ld)diff.x * diff.x + diff.y * diff.y);
            ans = max(ans, solve(xs, ys, new_p, mid_x, div));
        }
    }

    cout << fixed << setprecision(12) << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4052kb

input:

2
1 1 1
3 3 1

output:

1.000000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #2:

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

input:

3
4 5 5
4 6 7
1 3 8

output:

10.100505063388

result:

ok found '10.1005051', expected '10.1005051', error '0.0000000'

Test #3:

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

input:

2
0 0 1
1000000 1000000 1000000000

output:

1000000000.000000000000

result:

ok found '1000000000.0000000', expected '1000000000.0000000', error '0.0000000'

Test #4:

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

input:

20
328 207 21
365 145 188
347 79 41
374 335 699
288 250 97
32 267 131
296 332 434
2 91 36
139 43 21
26 455 696
57 135 410
14 500 396
255 181 646
103 114 593
309 351 787
207 316 138
440 416 806
413 349 695
413 201 501
455 396 442

output:

6092.442712623783

result:

ok found '6092.4427126', expected '6092.4427126', error '0.0000000'

Test #5:

score: 0
Accepted
time: 1ms
memory: 4124kb

input:

20
38 207 766
202 485 964
257 466 900
205 486 738
166 53 716
61 94 881
252 165 182
63 292 612
225 278 242
224 242 566
381 196 702
56 494 997
268 288 884
379 227 3
357 271 975
55 73 678
260 55 623
399 369 515
116 354 580
404 239 950

output:

11878.257312827460

result:

ok found '11878.2573128', expected '11878.2573128', error '0.0000000'

Test #6:

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

input:

20
249 215 320
38 48 229
457 366 56
36 142 186
44 96 935
97 190 143
215 218 123
116 486 291
304 232 463
429 297 29
479 475 97
97 198 405
69 395 121
381 121 926
137 197 972
410 91 218
87 421 737
117 390 144
319 287 170
353 302 754

output:

5573.255896932631

result:

ok found '5573.2558969', expected '5573.2558969', error '0.0000000'

Test #7:

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

input:

20
474 215 66
376 120 6
367 259 211
362 293 34
416 407 554
133 292 894
171 278 871
459 187 674
383 192 980
352 78 899
83 27 684
138 185 709
357 234 359
390 241 40
418 124 161
258 348 462
408 59 851
110 184 668
28 447 761
20 131 367

output:

8510.595617883409

result:

ok found '8510.5956179', expected '8510.5956179', error '0.0000000'

Test #8:

score: 0
Accepted
time: 7510ms
memory: 4048kb

input:

400
979422 264252 76260
922920 334464 58710
87057 798078 39652
602478 649867 49073
388746 161788 44501
727471 373113 28061
944959 505744 22145
191465 164645 49421
102241 771049 65953
44911 762286 34082
112779 537040 98117
688054 585935 53647
391845 931395 55355
788464 698271 91449
984533 409449 8331...

output:

35610300.744289875031

result:

ok found '35610300.7442899', expected '35610300.7442899', error '0.0000000'

Test #9:

score: 0
Accepted
time: 7503ms
memory: 4224kb

input:

400
972392 809281 95619
19054 872671 65516
732236 376176 38922
412232 147107 36902
242843 486112 34287
311141 416172 5612
453695 775962 79060
806457 678364 29585
324358 953486 58858
532543 378842 67089
20301 449627 86941
252735 242252 66239
335667 454693 40007
563783 444579 49920
663605 128448 3095
...

output:

35334006.330976821482

result:

ok found '35334006.3309768', expected '35334006.3309768', error '0.0000000'

Test #10:

score: 0
Accepted
time: 7515ms
memory: 4288kb

input:

400
718289 727141 23905
849810 500522 44241
890554 385825 70996
597411 423432 99133
994251 463004 32770
388843 280170 47562
664865 319482 48403
353770 474376 52218
508270 890719 28901
80661 697191 77469
459811 411012 23750
741501 408373 60551
163462 269625 56148
406785 260156 41900
337932 855364 578...

output:

36725958.767186872661

result:

ok found '36725958.7671869', expected '36725958.7671869', error '0.0000000'

Test #11:

score: 0
Accepted
time: 7504ms
memory: 4116kb

input:

400
6840 184362 43862
608935 154893 10000000
746897 683314 71237
255918 899062 94342
478185 102216 1923
890855 323689 44654
467417 577805 20
919997 267591 21891
303668 171438 29365
324647 818449 18945
229942 874921 22870
174645 613823 31193
559386 859851 36262
156698 936021 86194
968031 522125 75799...

output:

36590958.860493369401

result:

ok found '36590958.8604934', expected '36590958.8604934', error '0.0000000'

Test #12:

score: 0
Accepted
time: 7500ms
memory: 4052kb

input:

400
213928 419916 45837
334919 278535 7824
100882 416988 26147
682280 524709 85794
569137 589867 48913
344075 156956 4813
87794 655931 25690
285467 798402 55113
295984 894760 44628
535011 461670 72400
917862 461662 90830
544780 751382 81071
588022 966874 10000000
872058 880760 39315
216881 626161 22...

output:

46173511.871992319822

result:

ok found '46173511.8719923', expected '46173511.8719923', error '0.0000000'

Test #13:

score: 0
Accepted
time: 7512ms
memory: 4008kb

input:

400
937407 829281 77362
837708 843713 34574
77624 684540 68232
786430 452449 38426
486327 341660 86859
964636 122535 12764
699975 284575 84208
806142 721010 10955
464680 787842 37887
395874 727033 70790
59849 84503 90263
557124 876914 45080
168385 390089 16463
6894 13302 8291
380410 621577 47431
992...

output:

45704049.961534269154

result:

ok found '45704049.9615343', expected '45704049.9615343', error '0.0000000'

Test #14:

score: 0
Accepted
time: 7512ms
memory: 4004kb

input:

400
769436 473525 91179
925212 211008 73863
393798 496395 71452
241696 745916 92387
519975 24414 32489
867615 821099 81949
644522 605802 2383
237926 379309 38924
389221 50127 90627
201042 315597 28025
314735 422671 18588
616409 476289 21284
397182 521279 80524
190834 918992 35979
405770 829871 41232...

output:

46077961.212134361267

result:

ok found '46077961.2121344', expected '46077961.2121344', error '0.0000000'

Test #15:

score: 0
Accepted
time: 7507ms
memory: 4008kb

input:

400
661885 939867 75528
487494 846559 71593
290098 369543 36755
931898 794760 63921
480058 761470 19842
426135 379317 3551
627245 832185 26033
598705 59485 2540
941138 844706 6210
377586 312034 96388
398374 295001 41568
874081 558382 41501
933464 285407 30933
444410 590787 18450
950252 399446 44906
...

output:

45282826.919197022915

result:

ok found '45282826.9191970', expected '45282826.9191970', error '0.0000000'

Test #16:

score: 0
Accepted
time: 7508ms
memory: 4188kb

input:

400
569839 791389 68749
839674 777277 63933
863326 968947 6358
180942 20818 69013
875946 210141 10000000
321824 169791 90333
877709 273385 90285
135978 546433 47341
46246 441438 70141
12053 496729 17675
576117 666429 46856
197452 968179 51530
509363 87403 55583
193224 750277 97047
7722 889000 70489
...

output:

55534449.243508420885

result:

ok found '55534449.2435084', expected '55534449.2435084', error '0.0000000'

Test #17:

score: 0
Accepted
time: 7502ms
memory: 4088kb

input:

400
256630 187847 11194
897382 694378 18835
350562 923633 99933
205851 958234 8647
715754 266300 68929
684673 719293 82041
304184 162766 99040
699035 219131 15513
315331 32273 49150
339042 179271 60962
241294 982748 68635
660080 88445 99207
162427 641286 80190
199541 249437 72499
204956 414509 32836...

output:

56842720.232543796301

result:

ok found '56842720.2325438', expected '56842720.2325438', error '0.0000000'

Test #18:

score: 0
Accepted
time: 7504ms
memory: 3992kb

input:

400
891557 241099 10125
316914 425364 32054
657652 448853 28433
475110 718140 83424
425448 596023 65334
128996 426213 53829
813917 692602 28723
693896 817142 8591
16046 375611 26923
184028 990969 58048
498854 915662 79220
77435 469326 15270
775143 697151 56
20169 991072 37373
922109 871304 73982
369...

output:

55025500.341025002301

result:

ok found '55025500.3410250', expected '55025500.3410250', error '0.0000000'

Test #19:

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

input:

400
828767 606397 14986
448568 868264 52625
863674 833593 12260
21259 513438 86242
392594 387534 62680
397658 426280 79956
392196 731597 51319
57619 697219 15776
566541 946740 81803
858232 528140 60149
572906 197112 83601
167809 31160 61928
192638 668070 66133
988108 900482 83698
356771 210640 8457
...

output:

55207053.561489321291

result:

ok found '55207053.5614893', expected '55207053.5614893', error '0.0000000'

Test #20:

score: 0
Accepted
time: 7506ms
memory: 3996kb

input:

400
652930 388986 93092
175667 5066 79475
824559 456628 46198
405436 976444 9728
98439 824664 37902
133984 824519 62538
44592 247702 80017
956993 633946 8159
333726 672264 48680
929512 627435 71532
53499 861432 23848
254670 396688 79430
266385 903784 73840
775791 937341 40023
938364 85706 20447
9444...

output:

66199867.482260160148

result:

ok found '66199867.4822602', expected '66199867.4822602', error '0.0000000'

Test #21:

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

input:

400
327433 225448 72419
180629 560500 97932
246413 886763 87194
36579 660354 5583
576311 650681 58242
480636 727717 18522
522922 331330 57537
147188 727126 24744
718669 159276 33254
861143 15648 21698
727055 664167 5898
653626 350031 91550
723519 303309 73005
480206 179059 70729
219329 901693 73987
...

output:

65993994.757541067898

result:

ok found '65993994.7575411', expected '65993994.7575411', error '0.0000000'

Test #22:

score: -100
Wrong Answer
time: 7507ms
memory: 4064kb

input:

400
843902 857131 60014
26310 422832 50339
738436 522415 41915
169028 339593 61310
951478 200194 12415
730116 19247 56519
769040 958693 61076
405104 32233 57682
27255 130563 31613
748330 322448 11181
129992 265273 45001
764569 206047 21608
922901 189481 88493
551608 525267 82388
939239 414554 41669
...

output:

65858119.975207179785

result:

wrong answer 1st numbers differ - expected: '65858330.0232496', found: '65858119.9752072', error = '0.0000032'