Submission #341638

# Submission time Handle Problem Language Result Execution time Memory
341638 2020-12-30T10:37:26 Z beksultan04 K blocks (IZhO14_blocks) C++14
100 / 100
406 ms 81988 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define umax(a,b) a = max(a,b);
#define umin(a,b) a = min(a,b);
#define endi puts("");
#define eps 1e-12
const int N = 1e5+12,INF=1e9+7;
int dp[N][101],q[N];
main(){
    int n,k,i,j;
    scan2(n,k)
    for (i=1;i<=n;++i)
        scan1(q[i])
    for (i=0;i<=n;++i)
        for (j=0;j<=k;++j)dp[i][j]=INF;

    int mx = 0;

    for (i=1;i<=n;++i){
        umax(mx,q[i])
        dp[i][1]=mx;
    }

    for (j=2;j<=k;++j){

        vector <pii> v;

        for (i=j;i<=n;++i){
            int tmp = dp[i-1][j-1];
            while (!v.empty() && v.back().fr < q[i]){
                umin(tmp,v.back().sc);
                v.pop_back();
            }
            if (v.empty() || v.back().fr+v.back().sc > tmp+q[i]){
                v.pb({q[i],tmp});
            }
            dp[i][j] = v.back().fr+v.back().sc;

        }
    }
    cout <<dp[n][k];
}


Compilation message

blocks.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main(){
      |      ^
blocks.cpp: In function 'int main()':
blocks.cpp:15:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                          ^~~~~~~ ~~~~~~~~
      |                                  |
      |                                  long long int*
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17 | #define all(s) s.begin(),s.end()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 | #define allr(s) s.rbegin(),s.rend()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | #define pb push_back
      | ~~~~~~~~~~~~~~~~~~~~      
   20 | #define sz(v) (int)v.size()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | #define umax(a,b) a = max(a,b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 | #define umin(a,b) a = min(a,b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   23 | #define endi puts("");
      | ~~~~~~~~~~~~~~~~~~~~~~    
   24 | #define eps 1e-12
      | ~~~~~~~~~~~~~~~~~         
   25 | const int N = 1e5+12,INF=1e9+7;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 | int dp[N][101],q[N];
      | ~~~~~~~~~~~~~~~~~~~~      
   27 | main(){
      | ~~~~~~~                   
   28 |     int n,k,i,j;
      |     ~~~~~~~~~~~~          
   29 |     scan2(n,k)
      |     ~~~~~~~               
blocks.cpp:29:5: note: in expansion of macro 'scan2'
   29 |     scan2(n,k)
      |     ^~~~~
blocks.cpp:15:28: note: format string is defined here
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                           ~^
      |                            |
      |                            int*
      |                           %lld
blocks.cpp:15:26: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                          ^~~~~~~     ~~~~
      |                                      |
      |                                      long long int*
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17 | #define all(s) s.begin(),s.end()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 | #define allr(s) s.rbegin(),s.rend()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | #define pb push_back
      | ~~~~~~~~~~~~~~~~~~~~      
   20 | #define sz(v) (int)v.size()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | #define umax(a,b) a = max(a,b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 | #define umin(a,b) a = min(a,b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   23 | #define endi puts("");
      | ~~~~~~~~~~~~~~~~~~~~~~    
   24 | #define eps 1e-12
      | ~~~~~~~~~~~~~~~~~         
   25 | const int N = 1e5+12,INF=1e9+7;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 | int dp[N][101],q[N];
      | ~~~~~~~~~~~~~~~~~~~~      
   27 | main(){
      | ~~~~~~~                   
   28 |     int n,k,i,j;
      |     ~~~~~~~~~~~~          
   29 |     scan2(n,k)
      |     ~~~~~~~~~             
blocks.cpp:29:5: note: in expansion of macro 'scan2'
   29 |     scan2(n,k)
      |     ^~~~~
blocks.cpp:15:31: note: format string is defined here
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                              ~^
      |                               |
      |                               int*
      |                              %lld
blocks.cpp:14:24: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   14 | #define scan1(a) scanf("%d",&a);
      |                        ^~~~ ~~~~
      |                             |
      |                             long long int*
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   16 | #define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   17 | #define all(s) s.begin(),s.end()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 | #define allr(s) s.rbegin(),s.rend()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | #define pb push_back
      | ~~~~~~~~~~~~~~~~~~~~    
   20 | #define sz(v) (int)v.size()
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   21 | #define umax(a,b) a = max(a,b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 | #define umin(a,b) a = min(a,b);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   23 | #define endi puts("");
      | ~~~~~~~~~~~~~~~~~~~~~~  
   24 | #define eps 1e-12
      | ~~~~~~~~~~~~~~~~~       
   25 | const int N = 1e5+12,INF=1e9+7;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 | int dp[N][101],q[N];
      | ~~~~~~~~~~~~~~~~~~~~    
   27 | main(){
      | ~~~~~~~                 
   28 |     int n,k,i,j;
      |     ~~~~~~~~~~~~        
   29 |     scan2(n,k)
      |     ~~~~~~~~~~          
   30 |     for (i=1;i<=n;++i)
      |     ~~~~~~~~~~~~~~~~~~  
   31 |         scan1(q[i])
      |         ~~~~~~~~~~      
blocks.cpp:31:9: note: in expansion of macro 'scan1'
   31 |         scan1(q[i])
      |         ^~~~~
blocks.cpp:14:26: note: format string is defined here
   14 | #define scan1(a) scanf("%d",&a);
      |                         ~^
      |                          |
      |                          int*
      |                         %lld
blocks.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 | #define scan2(a,b) scanf("%d %d",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:29:5: note: in expansion of macro 'scan2'
   29 |     scan2(n,k)
      |     ^~~~~
blocks.cpp:14:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 | #define scan1(a) scanf("%d",&a);
      |                  ~~~~~^~~~~~~~~
blocks.cpp:31:9: note: in expansion of macro 'scan1'
   31 |         scan1(q[i])
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 0 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 0 ms 364 KB Output is correct
46 Correct 0 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 0 ms 364 KB Output is correct
50 Correct 0 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 0 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 0 ms 364 KB Output is correct
46 Correct 0 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 0 ms 364 KB Output is correct
50 Correct 0 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 8 ms 8300 KB Output is correct
59 Correct 22 ms 35820 KB Output is correct
60 Correct 27 ms 35820 KB Output is correct
61 Correct 78 ms 35820 KB Output is correct
62 Correct 285 ms 80236 KB Output is correct
63 Correct 56 ms 80108 KB Output is correct
64 Correct 157 ms 80108 KB Output is correct
65 Correct 1 ms 492 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 1132 KB Output is correct
70 Correct 1 ms 1132 KB Output is correct
71 Correct 17 ms 8300 KB Output is correct
72 Correct 6 ms 8300 KB Output is correct
73 Correct 10 ms 8300 KB Output is correct
74 Correct 23 ms 35820 KB Output is correct
75 Correct 29 ms 35820 KB Output is correct
76 Correct 78 ms 35820 KB Output is correct
77 Correct 295 ms 80236 KB Output is correct
78 Correct 56 ms 80108 KB Output is correct
79 Correct 154 ms 80108 KB Output is correct
80 Correct 51 ms 80108 KB Output is correct
81 Correct 72 ms 80108 KB Output is correct
82 Correct 297 ms 80236 KB Output is correct
83 Correct 1 ms 1132 KB Output is correct
84 Correct 1 ms 1132 KB Output is correct
85 Correct 24 ms 8560 KB Output is correct
86 Correct 6 ms 8428 KB Output is correct
87 Correct 10 ms 8560 KB Output is correct
88 Correct 23 ms 35820 KB Output is correct
89 Correct 31 ms 36652 KB Output is correct
90 Correct 130 ms 36764 KB Output is correct
91 Correct 406 ms 81988 KB Output is correct
92 Correct 57 ms 81252 KB Output is correct
93 Correct 215 ms 81964 KB Output is correct
94 Correct 6 ms 8300 KB Output is correct
95 Correct 18 ms 8300 KB Output is correct
96 Correct 1 ms 1132 KB Output is correct
97 Correct 1 ms 1132 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct