QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#556389 | #2299. Heating Up | qwqqwqqwqe | TL | 1034ms | 30992kb | C++17 | 1.5kb | 2024-09-10 17:33:15 | 2024-09-10 17:33:16 |
Judging History
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++) {
if (pas[ord[i].second]) continue;
ans = min(ans, runs(ord[i].second));
for (int j = pL; j <= pR;j++) {
pas[j] = true;
}
}
cout << ans;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7764kb
input:
4 10 20 15 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 34ms
memory: 28876kb
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: 31ms
memory: 30932kb
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: 1034ms
memory: 30992kb
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: 1ms
memory: 5772kb
input:
3 0 0 0
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 23ms
memory: 28868kb
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: 0ms
memory: 5632kb
input:
3 10000000000000 10000000000000 10000000000000
output:
10000000000000
result:
ok single line: '10000000000000'
Test #8:
score: 0
Accepted
time: 44ms
memory: 28932kb
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: 0ms
memory: 7668kb
input:
3 9 5 2
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 5760kb
input:
3 443 555 705
output:
443
result:
ok single line: '443'
Test #11:
score: 0
Accepted
time: 0ms
memory: 7732kb
input:
3 4716156205617 1471795665076 6443609220689
output:
3244360540541
result:
ok single line: '3244360540541'
Test #12:
score: 0
Accepted
time: 0ms
memory: 7744kb
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: 0ms
memory: 7760kb
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: 0ms
memory: 7804kb
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: 0ms
memory: 7768kb
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: 0ms
memory: 7848kb
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: 0ms
memory: 7780kb
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: 8076kb
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: 3ms
memory: 8080kb
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: 3ms
memory: 8072kb
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: -100
Time Limit Exceeded
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...