Submission #284239

# Submission time Handle Problem Language Result Execution time Memory
284239 2020-08-27T04:46:26 Z 문홍윤(#5761) Discharging (NOI20_discharging) C++17
100 / 100
474 ms 16888 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2e18;
const int inf=1e9;

struct DYNAMIC_LI_CHAO{
    struct NODE {
        LL st, fin;
        LL a, b;
        NODE *l, *r;
        NODE(){st=fin=a=0, b=llinf; l=r=0;}
    }*root;
    LL getfx(NODE* nd, LL num){
        if(num<=(nd->fin+nd->st)/2)return min(nd->a*num+nd->b, nd->l?getfx(nd->l, num):llinf);
        return min(nd->a*num+nd->b, nd->r?getfx(nd->r, num):llinf);
    }
    void in_LICHAO(NODE* nd, LL aa, LL bb){
        LL mid=(nd->fin+nd->st)/2;
        LL fr=nd->a*nd->st+nd->b;
        LL re=nd->a*nd->fin+nd->b;
        LL nfr=aa*nd->st+bb;
        LL nre=aa*nd->fin+bb;
        if(fr<=nfr&&re<=nre)return;
        if(fr>=nfr&&re>=nre){
            nd->a=aa;
            nd->b=bb;
            return;
        }
        if(!nd->l){
            nd->l=new NODE;
            nd->l->st=nd->st;
            nd->l->fin=mid;
        }
        if(!nd->r){
            nd->r=new NODE;
            nd->r->st=mid+1;
            nd->r->fin=nd->fin;
        }
        in_LICHAO(nd->l, aa, bb);
        in_LICHAO(nd->r, aa, bb);
    }
    LL getfx(LL a){return getfx(root, a);}
    void in(LL a, LL b){in_LICHAO(root, a, b);}
    DYNAMIC_LI_CHAO(){root=new NODE; root->st=1ll, root->fin=1000000000ll;}
}li;

int n;
LL arr[1000010], dp[1000010];

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%lld", &arr[i]);
        arr[i]=max(arr[i], arr[i-1]);
    }
    li.in((LL)n, 0ll);
    for(int i=1; i<=n; i++){
        dp[i]=li.getfx(arr[i]);
        li.in((LL)(n-i), dp[i]);
    }
    printf("%lld\n", dp[n]);
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Discharging.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |         scanf("%lld", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 402 ms 16632 KB Output is correct
17 Correct 409 ms 16668 KB Output is correct
18 Correct 338 ms 16728 KB Output is correct
19 Correct 430 ms 16756 KB Output is correct
20 Correct 396 ms 16760 KB Output is correct
21 Correct 403 ms 16760 KB Output is correct
22 Correct 441 ms 16748 KB Output is correct
23 Correct 399 ms 16764 KB Output is correct
24 Correct 415 ms 16724 KB Output is correct
25 Correct 424 ms 16724 KB Output is correct
26 Correct 416 ms 16760 KB Output is correct
27 Correct 474 ms 16788 KB Output is correct
28 Correct 404 ms 16760 KB Output is correct
29 Correct 452 ms 16828 KB Output is correct
30 Correct 421 ms 16888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 15992 KB Output is correct
2 Correct 169 ms 15992 KB Output is correct
3 Correct 179 ms 15992 KB Output is correct
4 Correct 171 ms 15952 KB Output is correct
5 Correct 161 ms 15992 KB Output is correct
6 Correct 163 ms 15992 KB Output is correct
7 Correct 165 ms 15992 KB Output is correct
8 Correct 179 ms 15992 KB Output is correct
9 Correct 169 ms 16104 KB Output is correct
10 Correct 169 ms 15992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 360 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 402 ms 16632 KB Output is correct
31 Correct 409 ms 16668 KB Output is correct
32 Correct 338 ms 16728 KB Output is correct
33 Correct 430 ms 16756 KB Output is correct
34 Correct 396 ms 16760 KB Output is correct
35 Correct 403 ms 16760 KB Output is correct
36 Correct 441 ms 16748 KB Output is correct
37 Correct 399 ms 16764 KB Output is correct
38 Correct 415 ms 16724 KB Output is correct
39 Correct 424 ms 16724 KB Output is correct
40 Correct 416 ms 16760 KB Output is correct
41 Correct 474 ms 16788 KB Output is correct
42 Correct 404 ms 16760 KB Output is correct
43 Correct 452 ms 16828 KB Output is correct
44 Correct 421 ms 16888 KB Output is correct
45 Correct 174 ms 15992 KB Output is correct
46 Correct 169 ms 15992 KB Output is correct
47 Correct 179 ms 15992 KB Output is correct
48 Correct 171 ms 15952 KB Output is correct
49 Correct 161 ms 15992 KB Output is correct
50 Correct 163 ms 15992 KB Output is correct
51 Correct 165 ms 15992 KB Output is correct
52 Correct 179 ms 15992 KB Output is correct
53 Correct 169 ms 16104 KB Output is correct
54 Correct 169 ms 15992 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 360 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 2 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 267 ms 16376 KB Output is correct
77 Correct 274 ms 16376 KB Output is correct
78 Correct 281 ms 16184 KB Output is correct
79 Correct 310 ms 16120 KB Output is correct
80 Correct 261 ms 16120 KB Output is correct
81 Correct 276 ms 16120 KB Output is correct
82 Correct 267 ms 16120 KB Output is correct
83 Correct 272 ms 16124 KB Output is correct
84 Correct 256 ms 16248 KB Output is correct
85 Correct 267 ms 16120 KB Output is correct
86 Correct 253 ms 16212 KB Output is correct
87 Correct 252 ms 16120 KB Output is correct
88 Correct 263 ms 16144 KB Output is correct
89 Correct 269 ms 16248 KB Output is correct
90 Correct 311 ms 16120 KB Output is correct
91 Correct 242 ms 16184 KB Output is correct
92 Correct 407 ms 16504 KB Output is correct
93 Correct 460 ms 16632 KB Output is correct
94 Correct 253 ms 16120 KB Output is correct
95 Correct 284 ms 16248 KB Output is correct
96 Correct 271 ms 16120 KB Output is correct
97 Correct 263 ms 16120 KB Output is correct
98 Correct 270 ms 16168 KB Output is correct
99 Correct 251 ms 16212 KB Output is correct
100 Correct 288 ms 16124 KB Output is correct