Submission #524073

# Submission time Handle Problem Language Result Execution time Memory
524073 2022-02-08T15:13:46 Z DanerZein Discharging (NOI20_discharging) C++14
100 / 100
731 ms 9788 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e6+10;
const ll MAX=1e9;
struct line{
  ll m,b;
  line(ll mm,ll bb){
    m=mm; b=bb;
  }
  ll eval(ll x){
    return m*x+b;
  }
  /*long double intersect(line l){
    return (long double)(b-l.b)/(l.m-m);
  }*/
   ll intersect(line l){
    ll le=1;
    ll ri=1;
    while(eval(ri)>l.eval(ri)){
      le=ri;
      ri*=2;
    }
    while(ri>le){
      ll mid=(le+ri)/2;
      if(eval(mid)<=l.eval(mid)) ri=mid;
      else le=mid+1;
    }
    return ri;
  }
};
ll val[MAX_N];
int main(){
  int n; cin>>n;
  for(int i=1;i<=n;i++){
    cin>>val[i];
    val[i]=max(val[i],val[i-1]);
  }
  deque<line> dq;
  dq.push_front({MAX,MAX});
  ll ans=0;
  for(int i=1;i<=n;i++){
    int t=dq.size();
    line nl={(n-i+1),ans};
    while(t>=2 && nl.intersect(dq[t-2])<=dq[t-1].intersect(dq[t-2])){
      dq.pop_back();
      t--;
    }
    dq.push_back(nl);
    while(dq.size()>=2 && dq[0].eval(val[i])>=dq[1].eval(val[i]))
      dq.pop_front();
    
    ans=dq.front().eval(val[i]);
  }
  cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 312 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 3 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 324 KB Output is correct
12 Correct 2 ms 304 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 312 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 2 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 3 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 324 KB Output is correct
12 Correct 2 ms 304 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 552 ms 9300 KB Output is correct
17 Correct 637 ms 9788 KB Output is correct
18 Correct 464 ms 9128 KB Output is correct
19 Correct 652 ms 9584 KB Output is correct
20 Correct 605 ms 9376 KB Output is correct
21 Correct 646 ms 9476 KB Output is correct
22 Correct 577 ms 9032 KB Output is correct
23 Correct 709 ms 9176 KB Output is correct
24 Correct 649 ms 9156 KB Output is correct
25 Correct 675 ms 9116 KB Output is correct
26 Correct 731 ms 9372 KB Output is correct
27 Correct 551 ms 9120 KB Output is correct
28 Correct 645 ms 9192 KB Output is correct
29 Correct 670 ms 9136 KB Output is correct
30 Correct 695 ms 9136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 663 ms 9124 KB Output is correct
2 Correct 656 ms 9028 KB Output is correct
3 Correct 666 ms 9080 KB Output is correct
4 Correct 683 ms 9008 KB Output is correct
5 Correct 662 ms 9120 KB Output is correct
6 Correct 668 ms 9044 KB Output is correct
7 Correct 682 ms 9120 KB Output is correct
8 Correct 657 ms 9272 KB Output is correct
9 Correct 670 ms 9156 KB Output is correct
10 Correct 679 ms 9116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 2 ms 304 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 2 ms 204 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 2 ms 300 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 2 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 312 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 2 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 2 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 204 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 2 ms 204 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 2 ms 304 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 2 ms 204 KB Output is correct
29 Correct 2 ms 204 KB Output is correct
30 Correct 552 ms 9300 KB Output is correct
31 Correct 637 ms 9788 KB Output is correct
32 Correct 464 ms 9128 KB Output is correct
33 Correct 652 ms 9584 KB Output is correct
34 Correct 605 ms 9376 KB Output is correct
35 Correct 646 ms 9476 KB Output is correct
36 Correct 577 ms 9032 KB Output is correct
37 Correct 709 ms 9176 KB Output is correct
38 Correct 649 ms 9156 KB Output is correct
39 Correct 675 ms 9116 KB Output is correct
40 Correct 731 ms 9372 KB Output is correct
41 Correct 551 ms 9120 KB Output is correct
42 Correct 645 ms 9192 KB Output is correct
43 Correct 670 ms 9136 KB Output is correct
44 Correct 695 ms 9136 KB Output is correct
45 Correct 663 ms 9124 KB Output is correct
46 Correct 656 ms 9028 KB Output is correct
47 Correct 666 ms 9080 KB Output is correct
48 Correct 683 ms 9008 KB Output is correct
49 Correct 662 ms 9120 KB Output is correct
50 Correct 668 ms 9044 KB Output is correct
51 Correct 682 ms 9120 KB Output is correct
52 Correct 657 ms 9272 KB Output is correct
53 Correct 670 ms 9156 KB Output is correct
54 Correct 679 ms 9116 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 2 ms 204 KB Output is correct
57 Correct 1 ms 308 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 2 ms 300 KB Output is correct
60 Correct 1 ms 308 KB Output is correct
61 Correct 2 ms 204 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 1 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 1 ms 204 KB Output is correct
67 Correct 1 ms 312 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 204 KB Output is correct
70 Correct 2 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 2 ms 204 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 312 KB Output is correct
76 Correct 585 ms 9152 KB Output is correct
77 Correct 603 ms 9068 KB Output is correct
78 Correct 546 ms 9204 KB Output is correct
79 Correct 557 ms 9120 KB Output is correct
80 Correct 636 ms 9048 KB Output is correct
81 Correct 530 ms 9124 KB Output is correct
82 Correct 546 ms 9284 KB Output is correct
83 Correct 590 ms 9120 KB Output is correct
84 Correct 569 ms 9056 KB Output is correct
85 Correct 619 ms 9220 KB Output is correct
86 Correct 518 ms 9012 KB Output is correct
87 Correct 519 ms 9120 KB Output is correct
88 Correct 579 ms 9156 KB Output is correct
89 Correct 534 ms 9232 KB Output is correct
90 Correct 528 ms 9200 KB Output is correct
91 Correct 522 ms 9076 KB Output is correct
92 Correct 714 ms 9032 KB Output is correct
93 Correct 645 ms 8864 KB Output is correct
94 Correct 486 ms 8808 KB Output is correct
95 Correct 632 ms 8936 KB Output is correct
96 Correct 512 ms 8736 KB Output is correct
97 Correct 549 ms 8636 KB Output is correct
98 Correct 537 ms 8500 KB Output is correct
99 Correct 522 ms 8668 KB Output is correct
100 Correct 540 ms 8352 KB Output is correct