QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#71821#3563. Treatment ProjectHe_Ren35 267ms199100kbC++231.6kb2023-01-12 01:24:472023-01-12 01:24:52

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-12 01:24:52]
  • Judged
  • Verdict: 35
  • Time: 267ms
  • Memory: 199100kb
  • [2023-01-12 01:24:47]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 5;
const int MAXP = MAXN * 2 + 10;
const ll linf = 0x3f3f3f3f3f3f3f3f;

array<int, 4> p[MAXN];
vector<pii> g[MAXP];

int main(void) {
    int d, n;
    scanf("%d%d", &d, &n);

    for (int i = 1; i <= n; ++i)
        scanf("%d%d%d%d", &p[i][0], &p[i][1], &p[i][2], &p[i][3]);

    int S = 2 * n + 1, T = 2 * n + 2;

    for (int i = 1; i <= n; ++i) {
        g[i].emplace_back(i + n, p[i][3]);

        if (p[i][1] == 1)
            g[S].emplace_back(i, 0);

        if (p[i][2] == d)
            g[i + n].emplace_back(T, 0);

        for (int j = 1; j <= n; ++j) {
            if (i == j)
                continue;

            if (p[i][2] + 1 - p[i][0] < p[j][1] - p[j][0])
                continue;

            if (p[i][2] + 1 + p[i][0] < p[j][1] + p[j][0])
                continue;

            g[i + n].emplace_back(j, 0);
        }
    }

    static ll dis[MAXP];
    static bool vis[MAXP];
    priority_queue< pair<ll, int>> q;
    memset(dis, 0x3f, sizeof(dis));
    dis[S] = 0;
    q.emplace(0, S);

    while (q.size()) {
        int u = q.top().second;
        q.pop();

        if (vis[u])
            continue;

        vis[u] = 1;

        for (auto it : g[u]) {
            int v = it.first;
            ll nxt = dis[u] + it.second;

            if (nxt < dis[v])
                dis[v] = nxt, q.emplace(-dis[v], v);
        }
    }

    if (dis[T] == linf)
        printf("-1");
    else
        printf("%lld", dis[T]);

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

1000000000 100000
1 811370001 811380000 1000000000
1 413190001 413200000 1000000000
1 462480001 462490000 1000000000
1 384860001 384870000 1000000000
1 543220001 543230000 1000000000
1 766300001 766310000 1000000000
1 348890001 348900000 1000000000
1 996350001 996360000 1000000000
1 302700001 302710...

output:


result:


Subtask #2:

score: 5
Accepted

Test #19:

score: 5
Accepted
time: 2ms
memory: 11624kb

input:

1 1
1000000000 1 1 1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #20:

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

input:

1000000000 16
6 2 2 1
4 999999997 999999999 4
2 999999997 1000000000 2
3 1 4 3
3 999999997 1000000000 3
5 999999998 999999999 3
6 999999999 999999999 1
2 1 4 2
6 3 999999998 1
999999987 1 1000000000 10
999999986 1 1000000000 10
999999985 1 1000000000 10
4 2 4 4
5 2 3 3
1 999999997 1000000000 1
1 1 4 1

output:

9

result:

ok single line: '9'

Test #21:

score: 0
Accepted
time: 2ms
memory: 11632kb

input:

1000000000 16
5 999999998 999999999 2
999999985 1 1000000000 8
5 2 3 3
2 1 4 2
4 2 4 3
6 3 999999998 1
1 999999997 1000000000 1
6 999999999 999999999 2
6 2 2 2
2 999999997 1000000000 2
3 999999997 1000000000 3
4 999999997 999999999 4
999999987 1 1000000000 10
1 1 4 1
999999986 1 1000000000 10
3 1 4 3

output:

8

result:

ok single line: '8'

Test #22:

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

input:

1000000000 16
200000001 3 100000003 1000000000
1 1 100000001 1000000000
400000001 5 100000005 1000000000
1 900000000 1000000000 1000000000
500000001 899999995 999999995 1000000000
500000001 6 100000006 1000000000
600000001 899999994 999999994 1000000000
700000001 500000001 999999993 1000000000
40000...

output:

16000000000

result:

ok single line: '16000000000'

Test #23:

score: 0
Accepted
time: 5ms
memory: 11716kb

input:

1000000000 16
100000001 2 100000001 1000000000
500000001 6 100000006 1000000000
300000001 899999997 999999997 1000000000
700000001 8 500000000 1000000000
400000001 899999996 999999996 1000000000
1 1 100000001 1000000000
100000001 899999999 999999999 1000000000
200000001 3 100000003 1000000000
600000...

output:

-1

result:

ok single line: '-1'

Test #24:

score: 0
Accepted
time: 2ms
memory: 11720kb

input:

1000000000 16
308520246 1 500000000 359755556
295655247 487135002 987135001 271593000
314734892 968055357 1000000000 312883746
410091097 1 500000000 101547816
395764591 485673495 985673494 629609944
392316197 982225101 1000000000 401923300
978742397 1 500000000 868693198
952345206 473602810 97360280...

output:

944232302

result:

ok single line: '944232302'

Test #25:

score: 0
Accepted
time: 5ms
memory: 11672kb

input:

1000000000 16
672706728 1 200000000 497504405
685823406 186883323 386883322 774982231
674014449 375074366 575074365 773000447
654139023 555198940 755198939 790219287
656808645 752529318 952529317 476720223
644457233 940177906 1000000000 664282982
959379929 1 200000000 786969801
978273081 181106849 3...

output:

3404859829

result:

ok single line: '3404859829'

Test #26:

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

input:

1000000000 16
540954071 1 10000000 710172197
540536129 9582059 19582058 536145072
539536499 18582429 28582428 814753471
539185649 28231579 38231578 620882859
538350203 37396133 47396132 386658616
539249992 46496344 56496343 870617207
539643763 56102573 66102572 904970863
539573301 66032111 76032110 ...

output:

-1

result:

ok single line: '-1'

Test #27:

score: 0
Accepted
time: 3ms
memory: 11660kb

input:

1000000000 16
491674089 1 500000000 336648490
539994271 451679820 951679819 469043391
517647080 929332630 1000000000 292857884
281124238 1 500000000 712418479
328708776 452415464 952415463 296084141
356807854 924316387 1000000000 648894560
660900926 1 500000000 384729282
657610483 496709559 99670955...

output:

1886981327

result:

ok single line: '1886981327'

Test #28:

score: 0
Accepted
time: 2ms
memory: 11408kb

input:

1000000000 16
838698042 1 200000000 534015959
858199116 180498928 380498927 504484211
839907744 362207557 562207556 898913833
847053449 555061853 755061852 910907433
860497726 741617577 941617576 171206653
867040700 935074604 1000000000 676192995
208351725 1 200000000 506499124
228113409 180238318 3...

output:

-1

result:

ok single line: '-1'

Test #29:

score: 0
Accepted
time: 2ms
memory: 11640kb

input:

1000000000 16
205846077 1 10000000 873895887
204858740 9012665 19012664 147782763
205674932 18196474 28196473 776792335
205398591 27920134 37920133 18876276
205275591 37797135 47797134 113374737
206002463 47070264 57070263 216570418
205456894 56524696 66524695 508488400
205480940 66500651 76500650 8...

output:

-1

result:

ok single line: '-1'

Test #30:

score: 0
Accepted
time: 5ms
memory: 11720kb

input:

1000000000 16
521719332 635760132 934417526 529743702
1305373 525299245 1000000000 461248301
101171661 237013303 513442486 519226146
461851512 227481783 939390202 642026488
835321835 380826656 1000000000 864581393
774758954 598049287 1000000000 885982602
476039441 1 226851442 609871787
583465229 392...

output:

1071400261

result:

ok single line: '1071400261'

Test #31:

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

input:

1000000000 16
206783888 1 794031651 473137665
654757441 181608545 482154540 814079812
199299059 172003379 589586500 977531496
445754685 647415391 1000000000 724703815
30495945 650569357 1000000000 700408250
370373056 15814055 569148871 97147596
592280811 734763422 1000000000 99025581
523660734 98269...

output:

926766012

result:

ok single line: '926766012'

Test #32:

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

input:

1000000000 16
53129883 43438614 576626916 420027795
595715370 217546351 904088926 117669374
501698138 394506898 1000000000 501348919
16794543 467166832 1000000000 430252715
66170783 44326969 740935026 307666284
100432574 105218928 612739989 964426597
66832107 59260547 587707946 695056263
71803431 40...

output:

1084276058

result:

ok single line: '1084276058'

Test #33:

score: 0
Accepted
time: 2ms
memory: 11668kb

input:

20 16
11 11 20 614196799
18 11 20 106915074
9 20 20 806710174
5 19 20 334176271
12 11 16 63935383
8 1 3 493767973
13 17 20 937825697
16 11 20 599156261
4 6 20 162982558
17 4 20 156235818
12 8 14 967709279
19 11 20 880182565
6 13 18 842507131
19 17 19 30861075
17 1 10 659432307
9 5 15 689432411

output:

815668125

result:

ok single line: '815668125'

Test #34:

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

input:

20 16
14 1 5 36860000
17 3 8 100853922
6 14 16 960259663
20 2 9 15251465
8 17 18 411813150
16 18 20 957718939
17 1 8 346305175
2 20 20 759532534
3 16 20 708800301
12 19 20 571134941
5 4 11 532379718
6 16 20 124294312
20 12 20 89050063
16 13 19 890357065
20 13 20 289577457
15 20 20 126485192

output:

-1

result:

ok single line: '-1'

Test #35:

score: 0
Accepted
time: 2ms
memory: 11576kb

input:

20 16
5 17 20 883046038
2 13 15 646298453
1 16 19 673045363
5 8 9 429038258
5 4 7 675052934
3 9 11 556330641
4 7 11 709314017
2 18 20 666670231
1 3 3 408856853
2 2 6 619870732
2 12 14 948839865
2 10 13 131394079
2 2 2 70988341
3 1 3 17741436
5 14 14 901591370
2 17 19 223748049

output:

-1

result:

ok single line: '-1'

Test #36:

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

input:

20 16
8 17 19 6
11 1 12 19
20 15 20 18
16 13 20 13
12 6 16 9
14 2 19 3
5 10 13 16
7 18 18 20
5 11 20 11
11 7 20 11
13 18 20 15
9 7 16 3
13 1 4 11
5 12 20 2
11 13 16 20
11 14 19 7

output:

19

result:

ok single line: '19'

Test #37:

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

input:

20 16
4 8 12 1
5 3 3 3
3 1 3 2
5 1 3 2
5 20 20 2
5 8 8 2
4 7 11 2
1 8 9 4
1 8 10 5
5 20 20 3
4 12 16 4
5 6 7 3
5 8 8 3
5 15 18 3
1 19 20 5
1 2 2 1

output:

-1

result:

ok single line: '-1'

Subtask #3:

score: 30
Accepted

Dependency #2:

100%
Accepted

Test #38:

score: 30
Accepted
time: 239ms
memory: 139564kb

input:

1000000000 5000
2157 2 343 342
684 999998751 1000000000 684
1022 999998751 1000000000 1022
991 999998751 1000000000 991
2291 999999792 999999999 208
47 1 1250 47
402 999998751 1000000000 402
1688 999999189 999999999 811
987 1 1250 987
1606 999999107 999999999 893
2304 999999805 999999999 195
685 999...

output:

2499

result:

ok single line: '2499'

Test #39:

score: 0
Accepted
time: 267ms
memory: 139396kb

input:

1000000000 5000
195 1 1250 195
564 1 1250 564
129 999998751 1000000000 129
1682 999999183 999999999 817
2204 2 296 295
1035 999998751 1000000000 1035
847 999998751 1000000000 847
1476 999998977 999999999 1023
1811 999999312 999999999 688
2472 2 28 27
1319 999998820 999999999 1180
61 1 1250 61
78 999...

output:

2498

result:

ok single line: '2498'

Test #40:

score: 0
Accepted
time: 110ms
memory: 14032kb

input:

1000000000 5000
757999622 10002618 12002617 1000000000
295999853 4001147 6001146 1000000000
379999811 12003185 14003184 1000000000
103999949 2000949 4000948 1000000000
565999718 18004710 20004709 1000000000
197999902 10002898 12002897 1000000000
335999833 169 2000168 1000000000
355999823 12003173 14...

output:

5000000000000

result:

ok single line: '5000000000000'

Test #41:

score: 0
Accepted
time: 102ms
memory: 14336kb

input:

1000000000 5000
217999892 18004884 20004883 1000000000
91999955 12003041 14003040 1000000000
725999638 18004630 20004629 1000000000
601999700 8002298 10002297 1000000000
437999782 14003776 16003775 1000000000
265999868 4001132 6001131 1000000000
889999556 2000556 4000555 1000000000
937999532 470 200...

output:

-1

result:

ok single line: '-1'

Test #42:

score: 0
Accepted
time: 149ms
memory: 103728kb

input:

1000000000 5000
320666835 1 200000000 187217853
322526939 198139897 398139896 631767388
323529367 397137469 597137468 496959374
321841766 595449868 795449867 620561126
322858692 794432942 994432941 681543718
323529475 993762159 1000000000 986545860
885805421 1 200000000 676801183
886545538 199259884...

output:

123063672

result:

ok single line: '123063672'

Test #43:

score: 0
Accepted
time: 84ms
memory: 74532kb

input:

1000000000 5000
745611209 1 20000000 715651313
745680002 19931208 39931207 402698748
745755872 39855338 59855337 288321567
745938511 59672699 79672698 602888599
745770728 79504916 99504915 659069258
745685242 99419430 119419429 273198983
745562217 119296405 139296404 178746774
745546744 139280932 15...

output:

14163571828

result:

ok single line: '14163571828'

Test #44:

score: 0
Accepted
time: 105ms
memory: 71752kb

input:

1000000000 5000
112753424 1 2000000 913062593
112739395 1985972 3985971 166281708
112730420 3976997 5976996 580451332
112721071 5967648 7967647 561368637
112716937 7963514 9963513 715676377
112732367 9948084 11948083 537584086
112741031 11939420 13939419 292675267
112741126 13939325 15939324 3439499...

output:

248584753293

result:

ok single line: '248584753293'

Test #45:

score: 0
Accepted
time: 99ms
memory: 85476kb

input:

1000000000 5000
808230331 1 300000 43999410
808231945 298387 598386 90475405
808230452 596894 896893 876469028
808227612 894054 1194053 922246629
808228360 1193306 1493305 179771938
808229492 1492174 1792173 278935746
808228404 1791086 2091085 892173746
808231066 2088424 2388423 128812805
808233395 ...

output:

1683442292004

result:

ok single line: '1683442292004'

Test #46:

score: 0
Accepted
time: 156ms
memory: 103112kb

input:

1000000000 5000
401249082 1 200000000 920491430
399495207 198246127 398246126 249417395
399826536 397914799 597914798 748877841
400752881 596988455 796988454 907417173
402159614 795581723 995581722 135958240
403539588 994201750 1000000000 25492362
671577003 1 200000000 777341154
672292425 199284580 ...

output:

186911801

result:

ok single line: '186911801'

Test #47:

score: 0
Accepted
time: 110ms
memory: 73780kb

input:

1000000000 5000
232472239 1 20000000 713761443
232392941 19920704 39920703 741651619
232501468 39812178 59812177 14498992
232399063 59709774 79709773 999129630
232398402 79709114 99709113 887346137
232311738 99622451 119622450 150396004
232469824 119464366 139464365 633967062
232372864 139367407 159...

output:

50513374632

result:

ok single line: '50513374632'

Test #48:

score: 0
Accepted
time: 104ms
memory: 81580kb

input:

1000000000 5000
383539588 1 2000000 196715675
383533267 1993681 3993680 264028353
383520149 3980564 5980563 262446104
383503405 5963821 7963820 607613258
383521627 7945600 9945599 543170680
383513509 9937483 11937482 695813979
383517437 11933556 13933555 282402610
383529983 13921011 15921010 1361849...

output:

-1

result:

ok single line: '-1'

Test #49:

score: 0
Accepted
time: 82ms
memory: 87076kb

input:

1000000000 5000
726375412 1 300000 351886860
726373843 298433 598432 606710275
726373467 598058 898057 697117103
726375744 895782 1195781 190941467
726377079 1194448 1494447 656368106
726379835 1491693 1791692 375013198
726380226 1791303 2091302 973079150
726383110 2088420 2388419 836103301
72638396...

output:

-1

result:

ok single line: '-1'

Test #50:

score: 0
Accepted
time: 254ms
memory: 130924kb

input:

1000000000 5000
671385932 191166426 574562428 819068448
416904809 882132733 1000000000 445015983
882601166 773100419 1000000000 680649449
289832356 507463117 1000000000 402881354
893638448 382183115 859270310 294271111
180793943 817397728 1000000000 780380576
123575156 663535344 877510038 118371373
...

output:

620783455

result:

ok single line: '620783455'

Test #51:

score: 0
Accepted
time: 220ms
memory: 199064kb

input:

1000000000 5000
99450 344354789 1000000000 729115481
927422 299870321 378553946 514527062
935604 10676391 70216351 29268923
468308 338280859 386146861 232446023
490002 53418218 403888826 873541966
190796 524972303 1000000000 234913438
191467 183894576 767698203 454389112
893679 834068169 1000000000 ...

output:

161589786

result:

ok single line: '161589786'

Test #52:

score: 0
Accepted
time: 233ms
memory: 130288kb

input:

1000000000 5000
444 52389522 61880965 139385
4419 516783503 520980606 465435995
2780 866790887 875891659 371084291
1325 892480383 894980778 722763168
2331 593580028 601723156 189138320
1095 260328208 267441089 470387484
3469 126734096 136062224 500271727
748 120626888 129161489 525354866
4149 150764...

output:

12146871901

result:

ok single line: '12146871901'

Test #53:

score: 0
Accepted
time: 246ms
memory: 131088kb

input:

1000000000 5000
312791758 633717514 934039952 6
813610687 963644804 1000000000 3
993908575 752408978 1000000000 5
499538805 975159739 1000000000 1
976331544 810280188 1000000000 8
241457781 552997077 584011452 8
466166985 490564740 761892078 3
834562158 502538343 820561438 9
181289127 909382403 1000...

output:

2

result:

ok single line: '2'

Test #54:

score: 0
Accepted
time: 204ms
memory: 199100kb

input:

1000000000 5000
802937 787859444 790890981 3
122444 52886017 158152359 4
935119 523480777 1000000000 3
186748 456804343 986555414 6
757695 758426090 1000000000 4
828815 311815954 355318073 3
776915 942265819 1000000000 10
507072 527244135 686310255 5
27186 67238838 314997238 10
979059 596366396 7604...

output:

3

result:

ok single line: '3'

Test #55:

score: 0
Accepted
time: 170ms
memory: 129952kb

input:

1000000000 5000
1200 731737246 733911664 4
3161 777049953 780912302 10
4546 950327002 952835432 4
2747 11761580 13314493 3
446 980032453 983209259 2
4342 85921856 93203729 4
3231 87962829 91383678 9
3808 963865247 973447644 4
3864 834694059 837127707 5
3281 432100113 433971672 10
1892 947160670 9563...

output:

228

result:

ok single line: '228'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%