답안 #524071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524071 2022-02-08T15:12:17 Z DanerZein Discharging (NOI20_discharging) C++14
100 / 100
385 ms 17932 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 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 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 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 204 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 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 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 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 204 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 244 ms 8940 KB Output is correct
17 Correct 273 ms 9464 KB Output is correct
18 Correct 224 ms 8644 KB Output is correct
19 Correct 281 ms 9504 KB Output is correct
20 Correct 268 ms 9492 KB Output is correct
21 Correct 281 ms 9572 KB Output is correct
22 Correct 252 ms 8640 KB Output is correct
23 Correct 294 ms 8964 KB Output is correct
24 Correct 265 ms 8656 KB Output is correct
25 Correct 296 ms 8628 KB Output is correct
26 Correct 295 ms 8876 KB Output is correct
27 Correct 242 ms 8744 KB Output is correct
28 Correct 272 ms 8644 KB Output is correct
29 Correct 272 ms 8772 KB Output is correct
30 Correct 280 ms 8692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 8788 KB Output is correct
2 Correct 374 ms 17708 KB Output is correct
3 Correct 378 ms 17744 KB Output is correct
4 Correct 368 ms 17772 KB Output is correct
5 Correct 368 ms 17708 KB Output is correct
6 Correct 370 ms 17672 KB Output is correct
7 Correct 363 ms 17716 KB Output is correct
8 Correct 367 ms 17812 KB Output is correct
9 Correct 365 ms 17828 KB Output is correct
10 Correct 385 ms 17932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 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 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 332 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 308 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 1 ms 304 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 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 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 244 ms 8940 KB Output is correct
31 Correct 273 ms 9464 KB Output is correct
32 Correct 224 ms 8644 KB Output is correct
33 Correct 281 ms 9504 KB Output is correct
34 Correct 268 ms 9492 KB Output is correct
35 Correct 281 ms 9572 KB Output is correct
36 Correct 252 ms 8640 KB Output is correct
37 Correct 294 ms 8964 KB Output is correct
38 Correct 265 ms 8656 KB Output is correct
39 Correct 296 ms 8628 KB Output is correct
40 Correct 295 ms 8876 KB Output is correct
41 Correct 242 ms 8744 KB Output is correct
42 Correct 272 ms 8644 KB Output is correct
43 Correct 272 ms 8772 KB Output is correct
44 Correct 280 ms 8692 KB Output is correct
45 Correct 362 ms 8788 KB Output is correct
46 Correct 374 ms 17708 KB Output is correct
47 Correct 378 ms 17744 KB Output is correct
48 Correct 368 ms 17772 KB Output is correct
49 Correct 368 ms 17708 KB Output is correct
50 Correct 370 ms 17672 KB Output is correct
51 Correct 363 ms 17716 KB Output is correct
52 Correct 367 ms 17812 KB Output is correct
53 Correct 365 ms 17828 KB Output is correct
54 Correct 385 ms 17932 KB Output is correct
55 Correct 1 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 300 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 296 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 1 ms 300 KB Output is correct
63 Correct 1 ms 332 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 308 KB Output is correct
67 Correct 1 ms 204 KB Output is correct
68 Correct 1 ms 204 KB Output is correct
69 Correct 1 ms 204 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 204 KB Output is correct
72 Correct 1 ms 304 KB Output is correct
73 Correct 1 ms 304 KB Output is correct
74 Correct 1 ms 304 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 279 ms 14044 KB Output is correct
77 Correct 267 ms 14116 KB Output is correct
78 Correct 253 ms 13472 KB Output is correct
79 Correct 259 ms 13780 KB Output is correct
80 Correct 279 ms 14416 KB Output is correct
81 Correct 248 ms 13576 KB Output is correct
82 Correct 262 ms 13604 KB Output is correct
83 Correct 276 ms 13972 KB Output is correct
84 Correct 267 ms 13816 KB Output is correct
85 Correct 280 ms 14096 KB Output is correct
86 Correct 249 ms 13500 KB Output is correct
87 Correct 246 ms 13448 KB Output is correct
88 Correct 274 ms 13812 KB Output is correct
89 Correct 255 ms 13640 KB Output is correct
90 Correct 255 ms 13544 KB Output is correct
91 Correct 273 ms 13380 KB Output is correct
92 Correct 309 ms 14576 KB Output is correct
93 Correct 269 ms 14016 KB Output is correct
94 Correct 246 ms 12956 KB Output is correct
95 Correct 275 ms 14568 KB Output is correct
96 Correct 242 ms 13280 KB Output is correct
97 Correct 255 ms 13620 KB Output is correct
98 Correct 264 ms 13820 KB Output is correct
99 Correct 251 ms 13616 KB Output is correct
100 Correct 270 ms 13548 KB Output is correct