Submission #341637

# Submission time Handle Problem Language Result Execution time Memory
341637 2020-12-30T10:36:49 Z beksultan04 K blocks (IZhO14_blocks) C++14
0 / 100
1000 ms 364 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);
            }
            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 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 Execution timed out 1093 ms 364 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 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 0 ms 364 KB Output is correct
7 Execution timed out 1095 ms 364 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 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 1 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 Execution timed out 1093 ms 364 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 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 1 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 Execution timed out 1093 ms 364 KB Time limit exceeded
8 Halted 0 ms 0 KB -