Submission #231175

# Submission time Handle Problem Language Result Execution time Memory
231175 2020-05-13T01:42:48 Z infinite_iq K blocks (IZhO14_blocks) C++14
100 / 100
404 ms 87836 KB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 547
//#define mp make_pair
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ll mod=1e9+7;
const ld pai=acos(-1);
ll n , k ;
ll a[100009] ;
ll dp [100009][109] ;
int main () {
        scanf("%lld%lld",&n,&k) ;
        for ( int i = 1 ; i <= n ; i ++ ) scanf("%lld",&a[i]) ;
        for ( int i = 1 ; i <= n ; i ++ ) {
                dp [i][1] = max ( dp [i-1][1] , a[i] ) ;
        }
        dp [0][1] = inf ;
        for ( int i = 0 ; i <= n ; i ++ ) {
                for ( int j = 2 ; j <= k ; j ++ ) {
                        dp [i][j] = inf ;
                }
        }
        for ( int j = 2 ; j <= k ; j ++ ) {
                stack < pll > st ;
                for ( int i = 1 ; i <  j ; i ++ ) st .push ( { i , dp [i][j-1] } ) ;
                for ( int i = j ; i <= n ; i ++ ) {
                        ll val1 = dp[i-1][j-1] , val2 = inf ;
                        while ( st . size () ) {
                                ll id = st.top ().fi , crnt = st.top().se ;
                                if ( a [id] > a[i] ) break ;
                                val1 = min ( val1 , crnt ) ;
                                st .pop () ;
                        }
                        if ( st . size () ) val2 = dp [st.top().fi][j] ;
                        st .push ( { i , val1  } ) ;
                        val1 += a[i] ;
                        dp [i][j] = min ( val1 , val2 ) ;
                }
        }
        cout << dp[n][k] << endl ;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&n,&k) ;
         ~~~~~^~~~~~~~~~~~~~~~~~
blocks.cpp:36:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for ( int i = 1 ; i <= n ; i ++ ) scanf("%lld",&a[i]) ;
                                           ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8960 KB Output is correct
2 Correct 26 ms 38528 KB Output is correct
3 Correct 35 ms 38528 KB Output is correct
4 Correct 101 ms 38616 KB Output is correct
5 Correct 313 ms 87152 KB Output is correct
6 Correct 59 ms 87032 KB Output is correct
7 Correct 170 ms 87160 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 5 ms 1152 KB Output is correct
14 Correct 36 ms 8960 KB Output is correct
15 Correct 10 ms 8960 KB Output is correct
16 Correct 16 ms 8960 KB Output is correct
17 Correct 29 ms 38912 KB Output is correct
18 Correct 36 ms 38912 KB Output is correct
19 Correct 128 ms 38904 KB Output is correct
20 Correct 385 ms 87032 KB Output is correct
21 Correct 61 ms 87036 KB Output is correct
22 Correct 206 ms 87160 KB Output is correct
23 Correct 52 ms 87032 KB Output is correct
24 Correct 87 ms 87032 KB Output is correct
25 Correct 386 ms 87160 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 35 ms 9088 KB Output is correct
29 Correct 10 ms 9088 KB Output is correct
30 Correct 16 ms 9088 KB Output is correct
31 Correct 26 ms 38912 KB Output is correct
32 Correct 35 ms 39168 KB Output is correct
33 Correct 129 ms 39232 KB Output is correct
34 Correct 404 ms 87836 KB Output is correct
35 Correct 59 ms 87732 KB Output is correct
36 Correct 214 ms 87728 KB Output is correct
37 Correct 10 ms 8960 KB Output is correct
38 Correct 31 ms 8960 KB Output is correct
39 Correct 5 ms 1280 KB Output is correct
40 Correct 5 ms 1152 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct