QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#845958#9961. Cowsucup-team004AC ✓34ms3984kbC++232.3kb2025-01-06 20:34:022025-01-06 20:34:02

Judging History

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

  • [2025-01-06 20:34:02]
  • 评测
  • 测评结果:AC
  • 用时:34ms
  • 内存:3984kb
  • [2025-01-06 20:34:02]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }
    
    auto check = [&](int x) {
        int l[2], r[2];
        int s = 0;
        for (int i = 0; i < n; i++) {
            if (s >= 0) {
                int cur = 0;
                int res = h[i];
                for (int j = 0; j < s; j++) {
                    if (l[j] - cur >= res) {
                        cur += res;
                        res = 0;
                        break;
                    }
                    res -= l[j] - cur;
                    cur = l[j];
                    if (2 * (r[j] - cur) >= res) {
                        cur += (res + 1) / 2;
                        res = 0;
                        break;
                    }
                    res -= 2 * (r[j] - cur);
                    cur = r[j];
                }
                if (res > x - cur) {
                    l[0] = x - (res + cur - x);
                    r[0] = x;
                    if (l[0] < 0) {
                        return false;
                    }
                    s = -1;
                } else {
                    l[0] = cur + res;
                    r[0] = x;
                    s = 1;
                }
            } else {
                if (h[i] <= l[0]) {
                    l[1] = r[0];
                    r[0] = l[0];
                    r[1] = x;
                    l[0] = h[i];
                    s = 2;
                } else {
                    r[0] = l[0];
                    l[0] = 2 * l[0] - h[i];
                    if (l[0] < 0) {
                        return false;
                    }
                    s = -1;
                }
            }
        }
        return s >= 0;
    };
    
    int lo = 0, hi = 1E9;
    while (lo < hi) {
        int x = (lo + hi) / 2;
        if (check(x)) {
            hi = x;
        } else {
            lo = x + 1;
        }
    }
    std::cout << lo << "\n";
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
5 4 0 4 6

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3
1 4 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1
1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #5:

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

input:

8
6 0 5 5 6 3 0 6

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

6
7 6 5 2 6 8

output:

7

result:

ok 1 number(s): "7"

Test #7:

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

input:

10
5 9 3 4 3 2 5 8 2 3

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

10
1 18 3 15 0 14 20 15 14 12

output:

14

result:

ok 1 number(s): "14"

Test #9:

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

input:

10
1 18 3 15 0 14 20 15 15 12

output:

15

result:

ok 1 number(s): "15"

Test #10:

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

input:

20
97 171 3 157 117 35 0 0 173 154 59 58 18 189 27 181 78 20 253 22

output:

100

result:

ok 1 number(s): "100"

Test #11:

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

input:

20
96 171 3 157 117 35 0 0 173 154 59 58 18 188 27 181 78 20 253 22

output:

99

result:

ok 1 number(s): "99"

Test #12:

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

input:

1000
593735308 82782684 48201198 606672331 542608382 778767270 477934211 44729051 264362294 224305033 653755557 885668853 118708751 883106152 840075111 736969436 245937442 943545017 520344248 725034355 640010480 177641398 4028045 527811023 508005025 452498275 65950769 521987921 497919638 401868301 4...

output:

798545293

result:

ok 1 number(s): "798545293"

Test #13:

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

input:

1000
593735308 82782684 48201198 606672331 542608382 778767270 477934211 44729051 264362294 224305033 653755557 885668853 118708751 883106152 840075111 736969436 245937442 943545017 520344248 725034355 640010480 177641398 4028045 527811023 508005025 452498275 65950769 521987921 497919638 401868301 4...

output:

798545294

result:

ok 1 number(s): "798545294"

Test #14:

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

input:

1000
870134339 241622285 382813722 29652671 397661468 288654672 145876238 865005872 351416470 296289588 923558811 85715804 938307829 465854288 539811343 188181196 319886369 236723857 711700821 498884670 696002586 862289696 926586527 475233599 90349521 532316792 261729967 936458764 258814580 49402015...

output:

782381316

result:

ok 1 number(s): "782381316"

Test #15:

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

input:

1000
154900835 362244282 133683941 144852820 410993487 59656968 278536670 91686065 395986164 177161073 96616862 136888208 324917324 189024418 312836428 65208649 265537645 196269190 196269110 196268843 196268472 196268404 254991552 137541760 196265755 396921681 93579719 21703528 57640717 57640723 576...

output:

216943021

result:

ok 1 number(s): "216943021"

Test #16:

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

input:

1000
407654746 26232266 26230431 48223500 4236533 435976355 14315869 574258720 52815217 15052766 485406902 164280922 98696096 131487727 131487726 497481908 21859940 26338202 17379042 435017575 193953580 216828326 171077134 193952721 193952722 193952725 418234198 38642150 70047431 7236818 38641404 50...

output:

216943020

result:

ok 1 number(s): "216943020"

Test #17:

score: 0
Accepted
time: 19ms
memory: 3644kb

input:

131072
308563645 236807753 148836474 894596760 540980272 462494882 990501246 670342265 433904999 446185837 808006869 655879987 677704125 562455648 829313560 203814094 176500104 748682646 108495700 651430146 473204800 516582951 280571619 444168407 222709295 330612220 777614222 141721332 981081779 346...

output:

882731805

result:

ok 1 number(s): "882731805"

Test #18:

score: 0
Accepted
time: 11ms
memory: 3872kb

input:

131073
577029516 392655911 392655905 392655907 392655896 392655883 392655878 392655874 392655869 392655862 392655857 392655849 392655832 392655833 392655824 392655824 392655808 392655806 392655799 392655793 392655789 392655783 392655785 392655777 392655778 392655765 392655761 392655751 392655752 392...

output:

484842712

result:

ok 1 number(s): "484842712"

Test #19:

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

input:

131073
343892941 343892950 343892955 343892960 343892965 343892968 343892970 343892975 343892979 343892983 343892981 343892986 343892987 343892995 343892994 343893000 343893004 343893006 343893005 343893010 343893013 343893014 343893020 343893022 343893025 343893026 343893028 343893028 343893037 343...

output:

484842711

result:

ok 1 number(s): "484842711"

Test #20:

score: 0
Accepted
time: 23ms
memory: 3884kb

input:

199943
194595233 30192589 30554731 30554732 206986561 104667170 94613723 99640274 99640272 209642103 27899673 50448912 5349195 27898688 27898694 27898695 228147901 81135178 81177207 81093015 81135103 186526047 114789068 24251775 208311239 59351132 59349785 96955799 21742061 213536810 56169203 200411...

output:

112393914

result:

ok 1 number(s): "112393914"

Test #21:

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

input:

199943
194595233 30192589 30554731 30554732 206986561 104667170 94613723 99640274 99640272 209642103 27899673 50448912 5349195 27898688 27898694 27898695 228147901 81135178 81177207 81093015 81135103 186526047 114789068 24251775 208311239 59351132 59349785 96955799 21742061 213536810 56169203 200411...

output:

112393913

result:

ok 1 number(s): "112393913"

Test #22:

score: 0
Accepted
time: 17ms
memory: 3852kb

input:

199958
32218763 32218766 32218772 32218772 32218778 32218782 32218786 32218788 32218791 32218798 32218801 32218805 32218809 32218807 32218808 32218817 32218814 32218821 32218823 32218828 32218828 32218828 32218835 32218841 32218838 32218839 32218844 32218847 32218854 32218851 32218856 32218855 32218...

output:

41577593

result:

ok 1 number(s): "41577593"

Test #23:

score: 0
Accepted
time: 18ms
memory: 3844kb

input:

199958
10867680 10867687 10867693 10867690 10867697 10867701 10867705 10867707 10867710 10867715 10867719 10867721 10867728 10867731 10867737 10867734 10867741 10867739 10867740 10867741 10867742 10867749 10867755 10867760 10867761 10867762 10867770 10867771 10867776 10867782 10867785 10867791 10867...

output:

41577592

result:

ok 1 number(s): "41577592"

Test #24:

score: 0
Accepted
time: 25ms
memory: 3832kb

input:

200000
19573542 19573547 103941556 783460 898083 898086 898088 94050596 13507079 94977557 3730956 27708309 27708311 87373209 9217154 12572451 5861064 104080143 11002374 17867682 4134948 11001233 73769618 332002 116856437 5205101 5205602 6358486 4049799 5203702 91224837 8509748 76036247 26189835 2618...

output:

41432856

result:

ok 1 number(s): "41432856"

Test #25:

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

input:

200000
19573542 19573547 103941556 783460 898083 898086 898088 94050596 13507079 94977557 3730956 27708309 27708311 87373209 9217154 12572451 5861064 104080143 11002374 17867682 4134948 11001233 73769618 332002 116856437 5205101 5205602 6358486 4049799 5203702 91224837 8509748 76036247 26189835 2618...

output:

41432855

result:

ok 1 number(s): "41432855"

Test #26:

score: 0
Accepted
time: 33ms
memory: 3920kb

input:

200000
900452513 110154921 259362420 341649845 112127310 672659183 903077704 460905208 457225572 969629731 367448207 719789958 947455039 738599723 202576763 66721434 80370300 380809235 53388398 285359627 531451446 192654278 242574428 688897642 350765952 473736646 86731969 473961111 372548960 2994354...

output:

877475050

result:

ok 1 number(s): "877475050"

Test #27:

score: 0
Accepted
time: 32ms
memory: 3892kb

input:

200000
900452513 110154921 259362420 341649845 112127310 672659183 903077704 460905208 457225572 969629731 367448207 719789958 947455039 738599723 202576763 66721434 80370300 380809235 53388398 285359627 531451446 192654278 242574428 688897642 350765952 473736646 86731969 473961111 372548960 2994354...

output:

877475051

result:

ok 1 number(s): "877475051"

Test #28:

score: 0
Accepted
time: 18ms
memory: 3984kb

input:

200000
106173048 464909641 868389650 352848449 354652199 319715919 694367807 317394183 52679354 707620179 280263010 661462338 247523646 787027401 75584158 718473040 679735641 960778130 715429058 570353813 777552771 364858877 344960823 70772115 928065359 628638387 555592455 98124097 173629922 9324656...

output:

913206785

result:

ok 1 number(s): "913206785"

Test #29:

score: 0
Accepted
time: 23ms
memory: 3888kb

input:

200000
18806911 12692039 71984821 38329092 4333613 0 130055838 0 31942256 11301089 38552423 30112492 30655441 0 130055838 0 86701231 974 83509239 2574594 43440502 0 130055838 0 49171736 2196801 50231978 70958475 10201467 0 130055838 0 40839958 18841727 102052764 17418282 671854 0 130055838 0 6585283...

output:

43351946

result:

ok 1 number(s): "43351946"

Test #30:

score: 0
Accepted
time: 22ms
memory: 3848kb

input:

200000
39665044 23303704 77875934 21057861 9652921 0 130055838 0 13269184 105035785 2450856 10199100 80337729 0 130055838 0 17018351 89691960 16491526 12486925 59991730 0 130055838 0 33560471 48153786 13913141 70152624 42494334 0 130055838 0 490995 7300004 6848645 117978462 6704120 0 130055838 0 424...

output:

43351947

result:

ok 1 number(s): "43351947"

Test #31:

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

input:

200000
1 3 0 0 8 2 9 0 18 0 1 1 6 5 10 1 6 0 18 0 3 7 4 8 2 1 2 0 18 0 6 4 2 2 10 3 9 0 18 0 5 0 8 10 6 2 4 0 18 0 2 10 1 2 0 4 0 0 18 0 5 8 7 3 5 2 0 0 18 0 5 6 4 3 2 6 2 0 18 0 4 9 4 1 5 0 10 0 18 0 5 10 0 3 6 0 10 0 18 0 10 1 5 6 9 1 2 0 18 0 4 9 5 9 0 6 9 0 18 0 1 6 2 1 9 2 10 0 18 0 4 3 1 4 7 2...

output:

6

result:

ok 1 number(s): "6"

Test #32:

score: 0
Accepted
time: 26ms
memory: 3840kb

input:

200000
1 3 0 0 8 2 9 0 18 0 1 1 6 5 10 1 6 0 18 0 3 7 4 8 2 1 2 0 18 0 6 4 2 2 10 3 9 0 18 0 5 0 8 10 6 2 4 0 18 0 2 10 1 2 0 4 0 0 18 0 5 8 7 3 5 2 0 0 18 0 5 6 4 3 2 6 2 0 18 0 4 9 4 1 5 0 10 0 18 0 5 10 0 3 6 0 10 0 18 0 10 1 5 6 9 1 2 0 18 0 4 9 5 9 0 6 9 0 18 0 1 6 2 1 9 2 10 0 18 0 4 3 1 4 7 2...

output:

7

result:

ok 1 number(s): "7"

Test #33:

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

input:

200000
165157342 222962766 10245447 411629219 256046824 3925386 112431397 145867172 170381992 261419476 0 600000000 0 29724318 174871257 311417162 270307607 1117739 5443033 25083987 388601471 1022060 395957675 0 600000000 0 124002267 316372149 112499890 166952911 124768489 46158792 313120037 1026890...

output:

200000000

result:

ok 1 number(s): "200000000"

Test #34:

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

input:

200000
165157342 222962766 10245447 411629219 256046824 3925386 112431397 145867172 170381992 261419476 0 600000000 0 29724318 174871257 311417162 270307607 1117739 5443033 25083987 388601471 1022060 395957675 0 600000000 0 124002267 316372149 112499890 166952911 124768489 46158792 313120037 1026890...

output:

200000001

result:

ok 1 number(s): "200000001"

Test #35:

score: 0
Accepted
time: 34ms
memory: 3936kb

input:

200000
178209926 95337170 196244627 166124438 68688037 1028457 258300628 159847050 4152823 75321129 68535633 313906022 66461183 42485635 25927067 255006633 45209348 376805751 7130499 4990475 288046941 249984075 38422702 1651801 866464 365601443 96384651 21476232 359311948 829388 71458646 226584868 2...

output:

142857142

result:

ok 1 number(s): "142857142"

Test #36:

score: 0
Accepted
time: 30ms
memory: 3980kb

input:

200000
178209926 95337170 196244627 166124438 68688037 1028457 258300628 159847050 4152823 75321129 68535633 313906022 66461183 42485635 25927067 255006633 45209348 376805751 7130499 4990475 288046941 249984075 38422702 1651801 866464 365601443 96384651 21476232 359311948 829388 71458646 226584868 2...

output:

142857143

result:

ok 1 number(s): "142857143"

Test #37:

score: 0
Accepted
time: 12ms
memory: 3856kb

input:

200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #38:

score: 0
Accepted
time: 15ms
memory: 3932kb

input:

199999
0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

99999

result:

ok 1 number(s): "99999"

Test #39:

score: 0
Accepted
time: 19ms
memory: 3936kb

input:

199999
0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

output:

100000

result:

ok 1 number(s): "100000"

Test #40:

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

input:

199999
100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

100000

result:

ok 1 number(s): "100000"

Test #41:

score: 0
Accepted
time: 15ms
memory: 3856kb

input:

199999
0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 10000...

output:

499997500

result:

ok 1 number(s): "499997500"

Test #42:

score: 0
Accepted
time: 14ms
memory: 3828kb

input:

200000
0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 10000...

output:

500000000

result:

ok 1 number(s): "500000000"

Test #43:

score: 0
Accepted
time: 9ms
memory: 3936kb

input:

200000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #44:

score: 0
Accepted
time: 29ms
memory: 3792kb

input:

200000
52 89 91 75 57 52 86 2 24 89 54 36 29 43 68 11 79 27 85 6 39 82 86 26 54 79 94 88 95 51 15 24 73 26 43 76 66 68 50 39 98 46 21 75 57 13 21 64 21 89 84 78 40 3 36 92 12 85 63 30 52 28 29 4 59 78 63 99 47 6 36 96 92 29 20 30 53 62 78 11 98 46 19 62 99 92 66 35 78 78 3 43 2 82 41 35 82 10 47 62 ...

output:

333333333

result:

ok 1 number(s): "333333333"

Extra Test:

score: 0
Extra Test Passed