QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135945 | #2299. Heating Up | mojospy | WA | 752ms | 31344kb | C++14 | 1.5kb | 2023-08-06 16:15:56 | 2023-08-06 16:15:59 |
Judging History
answer
#include<iostream>
#include<functional>
#include<queue>
#include<unordered_set>
using namespace std;
const int N=5e5+3;
typedef long long int ll;
ll a[N];
int n;
class cmp{
public:
bool operator()(const int i,const int j)const{
return a[i]>a[j];
}
};
int deal(int id){
if(id==n) return 0;
else if(id<0) return n-1;
else return id;
}
bool isvaild(ll d){
for(int i=0;i<n;++i){
ll num=d;
int rmax=0;
if(num>=a[i]){
priority_queue<int,vector<int>,cmp> q;
unordered_set<int> s;
s.insert(i);
rmax=max(rmax,i);
//cout<<a[i]<<" ";
//s.insert(deal(i+1));
//s.insert(deal(i-1));
s.insert(deal(i+1));
s.insert(deal(i-1));
//cout<<i<<" "<<deal(i+1)<<" "<<deal(i-1)<<" ";
q.push(deal(i+1));
q.push(deal(i-1));
num+=a[i];
bool flag=true;
while(!q.empty()){
if(num<a[q.top()]){
flag=false;
i=rmax;
break;
}
int cur=q.top();
q.pop();
rmax=max(cur,rmax);
num+=a[cur];
s.insert(cur);
if(s.find(deal(cur+1))==s.end()){
s.insert(deal(cur+1));
q.push(deal(cur+1));
}
if(s.find(deal(cur-1))==s.end()){
s.insert(deal(cur-1));
q.push(deal(cur-1));
}
}
//cout<<endl;
if(flag) return true;
}
}
return false;
}
int main(){
ll l=1e13+5,r=-1;
cin>>n;
for(int i=0;i<n;++i){
cin>>a[i];
l=min(l,a[i]);
r=max(r,a[i]);
}
while(l<=r){
ll mid=(r-l)/2+l;
if(isvaild(mid)){
r=mid-1;
}else{
l=mid+1;
}
}
cout<<l;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3500kb
input:
4 10 20 15 1
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 498ms
memory: 31076kb
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: 531ms
memory: 31164kb
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: 347ms
memory: 31344kb
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: 3456kb
input:
3 0 0 0
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 55ms
memory: 28164kb
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: 3476kb
input:
3 10000000000000 10000000000000 10000000000000
output:
10000000000000
result:
ok single line: '10000000000000'
Test #8:
score: 0
Accepted
time: 176ms
memory: 28216kb
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: 3440kb
input:
3 9 5 2
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
3 443 555 705
output:
443
result:
ok single line: '443'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
3 4716156205617 1471795665076 6443609220689
output:
3244360540541
result:
ok single line: '3244360540541'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3500kb
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: 3420kb
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: 3444kb
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: 3528kb
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: 2ms
memory: 3544kb
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: 3524kb
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: 2ms
memory: 3920kb
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: 6ms
memory: 3944kb
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: 16ms
memory: 4024kb
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: 119ms
memory: 28544kb
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: 230ms
memory: 31316kb
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: 752ms
memory: 31088kb
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: -100
Wrong Answer
time: 2ms
memory: 3560kb
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:
3454731542153
result:
wrong answer 1st lines differ - expected: '114695390678', found: '3454731542153'