Submission #284280

# Submission time Handle Problem Language Result Execution time Memory
284280 2020-08-27T06:55:23 Z 최은수(#5747) Discharging (NOI20_discharging) C++17
100 / 100
246 ms 45504 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
inline ll get(pl l,ll x)
{
    return l.fi*x+l.se;
}
struct node
{
    pl ln;
    int l,r;
    node(){ln=pl(0,INF),l=r=0;}
}t[1000010];
int tct;
int rt;
void put(int&n,int s,int e,pl l)
{
    if(s>e)
        return;
    if(n==0)
        n=++tct;
    pl ln=t[n].ln;
    if(get(l,s)>get(ln,s))
        swap(l,ln);
    if(get(l,e)<=get(ln,e))
    {
        t[n].ln=l;
        return;
    }
    int m=s+(e-s)/2;
    if(get(l,m)<get(ln,m))
    {
        t[n].ln=l;
        put(t[n].r,m+1,e,ln);
    }
    else
    {
        t[n].ln=ln;
        put(t[n].l,s,m-1,l);
    }
    return;
}
ll get(int n,int s,int e,int x)
{
    if(n==0)
        return INF;
    ll ret=get(t[n].ln,x);
    int m=s+(e-s)/2;
    if(x<m)
        ret=min(ret,get(t[n].l,s,m-1,x));
    if(x>m)
        ret=min(ret,get(t[n].r,m+1,e,x));
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int>v(n);
    for(int&t:v)
        cin>>t;
    {
        int mx=v[0];
        for(int&t:v)
            t=mx=max(mx,t);
    }
    v.insert(v.begin(),0);
    vector<ll>dp(n+1,0);
    for(int i=0;i++<n;)
    {
        put(rt,1,inf,pl(-(i-1),dp[i-1]));
        dp[i]=get(rt,1,inf,v[i])+(ll)v[i]*n;
    }
    cout<<dp[n]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 16 ms 23936 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 15 ms 23808 KB Output is correct
12 Correct 15 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 16 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 18 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 18 ms 23808 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 15 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 227 ms 40628 KB Output is correct
17 Correct 246 ms 41404 KB Output is correct
18 Correct 186 ms 39988 KB Output is correct
19 Correct 221 ms 41404 KB Output is correct
20 Correct 216 ms 41268 KB Output is correct
21 Correct 214 ms 41396 KB Output is correct
22 Correct 224 ms 41012 KB Output is correct
23 Correct 226 ms 42036 KB Output is correct
24 Correct 223 ms 41516 KB Output is correct
25 Correct 226 ms 41780 KB Output is correct
26 Correct 224 ms 42164 KB Output is correct
27 Correct 220 ms 40756 KB Output is correct
28 Correct 239 ms 41396 KB Output is correct
29 Correct 230 ms 41524 KB Output is correct
30 Correct 229 ms 42036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 45244 KB Output is correct
2 Correct 151 ms 45248 KB Output is correct
3 Correct 152 ms 45236 KB Output is correct
4 Correct 152 ms 45236 KB Output is correct
5 Correct 147 ms 45236 KB Output is correct
6 Correct 153 ms 45504 KB Output is correct
7 Correct 148 ms 45236 KB Output is correct
8 Correct 146 ms 45244 KB Output is correct
9 Correct 147 ms 45236 KB Output is correct
10 Correct 147 ms 45312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 16 ms 23936 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 15 ms 23808 KB Output is correct
12 Correct 15 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 15 ms 23808 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 15 ms 23808 KB Output is correct
23 Correct 18 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 18 ms 23808 KB Output is correct
26 Correct 16 ms 23808 KB Output is correct
27 Correct 15 ms 23808 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 15 ms 23808 KB Output is correct
30 Correct 13 ms 23852 KB Output is correct
31 Correct 13 ms 23808 KB Output is correct
32 Correct 14 ms 23808 KB Output is correct
33 Correct 14 ms 23808 KB Output is correct
34 Correct 14 ms 23808 KB Output is correct
35 Correct 13 ms 23808 KB Output is correct
36 Correct 13 ms 23808 KB Output is correct
37 Correct 14 ms 23808 KB Output is correct
38 Correct 13 ms 23808 KB Output is correct
39 Correct 14 ms 23808 KB Output is correct
40 Correct 14 ms 23808 KB Output is correct
41 Correct 13 ms 23808 KB Output is correct
42 Correct 14 ms 23808 KB Output is correct
43 Correct 13 ms 23808 KB Output is correct
44 Correct 13 ms 23808 KB Output is correct
45 Correct 14 ms 23808 KB Output is correct
46 Correct 13 ms 23808 KB Output is correct
47 Correct 14 ms 23808 KB Output is correct
48 Correct 14 ms 23808 KB Output is correct
49 Correct 14 ms 23808 KB Output is correct
50 Correct 13 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 15 ms 23808 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 16 ms 23936 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 15 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 15 ms 23808 KB Output is correct
12 Correct 15 ms 23808 KB Output is correct
13 Correct 15 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 15 ms 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 15 ms 23808 KB Output is correct
19 Correct 15 ms 23808 KB Output is correct
20 Correct 15 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 15 ms 23808 KB Output is correct
23 Correct 18 ms 23808 KB Output is correct
24 Correct 15 ms 23808 KB Output is correct
25 Correct 18 ms 23808 KB Output is correct
26 Correct 16 ms 23808 KB Output is correct
27 Correct 15 ms 23808 KB Output is correct
28 Correct 15 ms 23808 KB Output is correct
29 Correct 15 ms 23808 KB Output is correct
30 Correct 227 ms 40628 KB Output is correct
31 Correct 246 ms 41404 KB Output is correct
32 Correct 186 ms 39988 KB Output is correct
33 Correct 221 ms 41404 KB Output is correct
34 Correct 216 ms 41268 KB Output is correct
35 Correct 214 ms 41396 KB Output is correct
36 Correct 224 ms 41012 KB Output is correct
37 Correct 226 ms 42036 KB Output is correct
38 Correct 223 ms 41516 KB Output is correct
39 Correct 226 ms 41780 KB Output is correct
40 Correct 224 ms 42164 KB Output is correct
41 Correct 220 ms 40756 KB Output is correct
42 Correct 239 ms 41396 KB Output is correct
43 Correct 230 ms 41524 KB Output is correct
44 Correct 229 ms 42036 KB Output is correct
45 Correct 170 ms 45244 KB Output is correct
46 Correct 151 ms 45248 KB Output is correct
47 Correct 152 ms 45236 KB Output is correct
48 Correct 152 ms 45236 KB Output is correct
49 Correct 147 ms 45236 KB Output is correct
50 Correct 153 ms 45504 KB Output is correct
51 Correct 148 ms 45236 KB Output is correct
52 Correct 146 ms 45244 KB Output is correct
53 Correct 147 ms 45236 KB Output is correct
54 Correct 147 ms 45312 KB Output is correct
55 Correct 13 ms 23852 KB Output is correct
56 Correct 13 ms 23808 KB Output is correct
57 Correct 14 ms 23808 KB Output is correct
58 Correct 14 ms 23808 KB Output is correct
59 Correct 14 ms 23808 KB Output is correct
60 Correct 13 ms 23808 KB Output is correct
61 Correct 13 ms 23808 KB Output is correct
62 Correct 14 ms 23808 KB Output is correct
63 Correct 13 ms 23808 KB Output is correct
64 Correct 14 ms 23808 KB Output is correct
65 Correct 14 ms 23808 KB Output is correct
66 Correct 13 ms 23808 KB Output is correct
67 Correct 14 ms 23808 KB Output is correct
68 Correct 13 ms 23808 KB Output is correct
69 Correct 13 ms 23808 KB Output is correct
70 Correct 14 ms 23808 KB Output is correct
71 Correct 13 ms 23808 KB Output is correct
72 Correct 14 ms 23808 KB Output is correct
73 Correct 14 ms 23808 KB Output is correct
74 Correct 14 ms 23808 KB Output is correct
75 Correct 13 ms 23808 KB Output is correct
76 Correct 157 ms 41524 KB Output is correct
77 Correct 161 ms 41780 KB Output is correct
78 Correct 155 ms 41012 KB Output is correct
79 Correct 153 ms 41392 KB Output is correct
80 Correct 162 ms 41916 KB Output is correct
81 Correct 169 ms 41100 KB Output is correct
82 Correct 154 ms 41140 KB Output is correct
83 Correct 163 ms 41524 KB Output is correct
84 Correct 154 ms 41396 KB Output is correct
85 Correct 161 ms 41652 KB Output is correct
86 Correct 153 ms 41012 KB Output is correct
87 Correct 162 ms 40900 KB Output is correct
88 Correct 157 ms 41268 KB Output is correct
89 Correct 163 ms 41140 KB Output is correct
90 Correct 158 ms 41016 KB Output is correct
91 Correct 150 ms 40756 KB Output is correct
92 Correct 224 ms 42160 KB Output is correct
93 Correct 226 ms 41516 KB Output is correct
94 Correct 160 ms 40628 KB Output is correct
95 Correct 168 ms 42052 KB Output is correct
96 Correct 160 ms 40884 KB Output is correct
97 Correct 173 ms 41144 KB Output is correct
98 Correct 156 ms 41276 KB Output is correct
99 Correct 153 ms 41012 KB Output is correct
100 Correct 167 ms 41140 KB Output is correct