QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556399#2299. Heating UpqwqqwqqwqeTL 90ms30992kbC++171.5kb2024-09-10 17:39:532024-09-10 17:39:53

Judging History

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

  • [2024-09-10 17:39:53]
  • 评测
  • 测评结果:TL
  • 用时:90ms
  • 内存:30992kb
  • [2024-09-10 17:39:53]
  • 提交

answer


#include"bits/stdc++.h"
#define ll long long
using namespace std;

const int maxn = 1e6+5;
const ll INF = 5e18;
ll a[maxn];
int pas[maxn];
pair<ll,int> ord[maxn];
int n;
ll ans = INF;
int rep;

int pL, pR;

ll runs (int pos) {
    pL = 0, pR = 0;
    int l = pos - 1, r = pos + 1;
    ll sum = a[pos]+a[pos], res = a[pos];
    while (r-l-1 < n) {
        if (res >= ans) {
            res = INF;
            break;
        }
        if (a[l] < a[r]) {
            if (sum < a[l]) {
                pas[l] = true;
                if (!pL) pL = l;
                res += a[l] - sum;
                sum = a[l];
            }
            sum += a[l--];
        }
        else {
            if (sum < a[r]) {
                pas[r] = true;
                if (!pR) pR = r;
                res += a[r] - sum;
                sum = a[r];
            }
            sum += a[r++];     
        }
    }
    return res;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    a[0] = INF;
    a[n + n + 1] = INF;
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
        a[n + i] = a[i];
        ord[i] = {a[i], i};
        ord[n + i] = {a[i], n + i};
    }
    sort(ord + 1, ord + n + 1);
    ans = runs(ord[1].second); 
    for (int i = 1;i <= n+n;i++) {
        int x = ord[i].second;
        if (pas[x]) continue;
        if (pL <= x && x <= pR) continue;
        ans = min(ans, runs(x)); 
    }
    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
10 20 15 1

output:

9

result:

ok single line: '9'

Test #2:

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

input:

500000
1 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:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 37ms
memory: 28932kb

input:

500000
500000 499999 499998 499997 499996 499995 499994 499993 499992 499991 499990 499989 499988 499987 499986 499985 499984 499983 499982 499981 499980 499979 499978 499977 499976 499975 499974 499973 499972 499971 499970 499969 499968 499967 499966 499965 499964 499963 499962 499961 499960 499959...

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 66ms
memory: 30612kb

input:

500000
269655 357411 31288 467020 110496 411556 112354 389593 171879 31947 4478 451939 305813 353339 49648 499863 157385 370552 9830 451015 205703 127891 152977 102706 178312 99678 251482 407026 65794 348294 45973 39969 169990 115902 287834 225236 292268 427507 131002 392853 312830 353489 390159 370...

output:

13561

result:

ok single line: '13561'

Test #5:

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

input:

3
0 0 0

output:

0

result:

ok single line: '0'

Test #6:

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

input:

500000
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:

0

result:

ok single line: '0'

Test #7:

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

input:

3
10000000000000 10000000000000 10000000000000

output:

10000000000000

result:

ok single line: '10000000000000'

Test #8:

score: 0
Accepted
time: 57ms
memory: 28912kb

input:

500000
10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000000000 10000000...

output:

10000000000000

result:

ok single line: '10000000000000'

Test #9:

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

input:

3
9 5 2

output:

3

result:

ok single line: '3'

Test #10:

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

input:

3
443 555 705

output:

443

result:

ok single line: '443'

Test #11:

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

input:

3
4716156205617 1471795665076 6443609220689

output:

3244360540541

result:

ok single line: '3244360540541'

Test #12:

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

input:

10
9 4 10 4 2 2 2 4 1 10

output:

2

result:

ok single line: '2'

Test #13:

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

input:

10
437 194 316 8 760 5 240 658 951 36

output:

194

result:

ok single line: '194'

Test #14:

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

input:

10
7766206761324 4390096407416 5007750532908 6105856289679 8058953691162 7878324499767 198372065990 2561194123806 5270309573574 108952625948

output:

2510743383778

result:

ok single line: '2510743383778'

Test #15:

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

input:

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

output:

1

result:

ok single line: '1'

Test #16:

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

input:

1000
876 688 340 910 327 791 194 228 468 91 276 245 236 492 613 986 131 16 224 816 567 919 207 114 181 264 311 795 632 568 601 96 87 458 139 930 235 486 298 995 80 254 108 522 174 553 953 604 880 165 574 982 332 156 884 205 125 712 146 1000 644 595 388 325 341 96 378 750 0 733 976 572 630 581 252 26...

output:

81

result:

ok single line: '81'

Test #17:

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

input:

1000
4244476445981 4188008041459 1343004383823 4430976398873 2707281889836 9972518046105 3771690011425 9278910842226 9458266244956 6404668117946 1394635778532 7077743790553 8082228561075 6755386194521 7394605523559 1358052292721 7208404326898 2369146891376 6397957436808 8922154200087 4039707770071 3...

output:

941569522270

result:

ok single line: '941569522270'

Test #18:

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

input:

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

output:

1

result:

ok single line: '1'

Test #19:

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

input:

10000
503 224 821 855 343 35 399 822 512 417 644 624 149 462 32 590 663 563 166 996 566 215 811 33 650 788 934 83 697 927 763 817 74 322 75 772 793 906 151 242 718 460 299 921 498 862 323 441 439 708 322 864 965 194 126 374 578 793 4 791 782 212 143 920 308 415 663 739 103 925 562 873 402 777 262 13...

output:

43

result:

ok single line: '43'

Test #20:

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

input:

10000
7803527661501 2395353435002 4570545035827 9189376124397 4613753129310 337134819369 1771517168097 6923910338059 1805047473968 5919987687999 9377832980782 3088260997173 1648061138881 1769001301496 7474212099137 9697794622249 3014578785761 9277959749147 5392922696370 1678858571990 9998623397131 2...

output:

431788281471

result:

ok single line: '431788281471'

Test #21:

score: 0
Accepted
time: 61ms
memory: 30888kb

input:

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

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 74ms
memory: 30992kb

input:

500000
945 441 317 935 298 231 897 357 108 180 104 812 189 558 258 262 448 672 51 557 764 336 106 910 833 461 599 372 656 345 132 997 53 150 748 806 728 284 628 738 839 238 521 920 917 165 909 262 90 805 570 774 108 250 25 234 27 589 785 202 613 102 336 575 872 469 697 697 800 364 33 787 342 82 5 28...

output:

24

result:

ok single line: '24'

Test #23:

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

input:

500000
8915837115681 1854924308350 4983171063409 9326350649871 3777458241922 4011735663721 6194627458492 968523372193 9719827134355 9233303438062 5481508725626 3743774964152 9665944214496 70071673654 9122981525604 5317000871929 8175936807290 296801525625 3488614064184 7847932215143 4209793972634 412...

output:

263506680769

result:

ok single line: '263506680769'

Test #24:

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

input:

1000
692 162 2646232467 1661392687526 2434434 1113 211 1027044183775 22 838664463100 331 413541 6 7354866040419 78512 15716 1243876261117 2371446131 18277 162582936964 1 104 4143659288 3863 3618 986710438140 949203668452 8672248522792 1060827857035 355 128 8354978 335285 5311273591 617856 1672862 70...

output:

114695390678

result:

ok single line: '114695390678'

Test #25:

score: 0
Accepted
time: 90ms
memory: 30924kb

input:

500000
437933005416 785 14320 1397084437204 1791441286 1511814 1 22795 46344 62155 467420034 2972 40991 19947739744 2728130 24 17271937929 14950076324 12 98781715531 1557656287604 20142452764 15555981223 242 542336379 1360227458 8 44531139100 1480999054246 3494809 588 47251 209574 23836173 300185110...

output:

7990458392

result:

ok single line: '7990458392'

Test #26:

score: 0
Accepted
time: 70ms
memory: 30972kb

input:

500000
0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911 1073741823 2147483647 4294967295 8589934591 17179869183 34359738367 68719476735 137438953471 274877906943 5497558138...

output:

1

result:

ok single line: '1'

Test #27:

score: -100
Time Limit Exceeded

input:

500000
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1...

output:


result: