Submission #1040382

# Submission time Handle Problem Language Result Execution time Memory
1040382 2024-08-01T02:48:49 Z vjudge1 K blocks (IZhO14_blocks) C++14
53 / 100
1000 ms 86608 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009
#define ll long long 
#define pb push_back 
#define fi first 
#define se second 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ; 

typedef vector<int> vi ; 
typedef pair<int,int> pii ; 
typedef vector<pii> vii ; 

template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } 
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } 

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a >= mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ; 
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

int n , k ; 
int a [maxn] ;

int L [maxn][20] ; 

int dp [maxn][109] ; 
void build_rmq () 
{
	for ( int i = 1 ; i <= n ; i ++ ) L [i][0] = a[i] ; 
	for ( int j = 1 ; j <= __lg(n) ; j ++ ) 
	{
		for ( int i = 1 ; i <= n-(1<<j)+1 ; i ++ ) 
		{
			L [i][j] = max (L[i][j-1],L[i+(1<<(j-1))][j-1]) ; 
		}
	}
}
int get ( int l , int r ) 
{
	int x = __lg(r-l+1) ; 
	return max (L[l][x],L[r-(1<<x)+1][x]) ;
} 
int main () 
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0); 
//	rf () ; 	
	cin >> n >> k ; 
	for ( int i = 1 ; i <= n ; i ++ ) cin >> a [i] ; 
	build_rmq () ; 
	
	memset ( dp,0x3f,sizeof dp) ; 

	dp [0][0] = 0 ; 

	for ( int i = 1 ; i <= n ; i ++ )
	{
		for ( int t = k ; t >= 1 ; t -- ) 
		{
			for ( int j = 1 ; j <= i ; j ++ ) 
			{
				chkmin (dp[i][t],dp[j-1][t-1]+get(j,i)) ; 
			}
		}
	}
	cout << dp [n][k] ; 
}

Compilation message

blocks.cpp: In function 'void rf()':
blocks.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 35 ms 85588 KB Output is correct
2 Correct 36 ms 85636 KB Output is correct
3 Correct 34 ms 85664 KB Output is correct
4 Correct 35 ms 85588 KB Output is correct
5 Correct 35 ms 85588 KB Output is correct
6 Correct 35 ms 85736 KB Output is correct
7 Correct 34 ms 85592 KB Output is correct
8 Correct 32 ms 85780 KB Output is correct
9 Correct 36 ms 85572 KB Output is correct
10 Correct 34 ms 85616 KB Output is correct
11 Correct 38 ms 85764 KB Output is correct
12 Correct 35 ms 85564 KB Output is correct
13 Correct 35 ms 85584 KB Output is correct
14 Correct 36 ms 85588 KB Output is correct
15 Correct 35 ms 85588 KB Output is correct
16 Correct 34 ms 85616 KB Output is correct
17 Correct 32 ms 85588 KB Output is correct
18 Correct 34 ms 85584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 85584 KB Output is correct
2 Correct 34 ms 85592 KB Output is correct
3 Correct 35 ms 85588 KB Output is correct
4 Correct 37 ms 85652 KB Output is correct
5 Correct 34 ms 85584 KB Output is correct
6 Correct 34 ms 85616 KB Output is correct
7 Correct 34 ms 85596 KB Output is correct
8 Correct 36 ms 85604 KB Output is correct
9 Correct 35 ms 85748 KB Output is correct
10 Correct 37 ms 85596 KB Output is correct
11 Correct 34 ms 85600 KB Output is correct
12 Correct 33 ms 85724 KB Output is correct
13 Correct 34 ms 85580 KB Output is correct
14 Correct 33 ms 85588 KB Output is correct
15 Correct 36 ms 85584 KB Output is correct
16 Correct 35 ms 85584 KB Output is correct
17 Correct 33 ms 85596 KB Output is correct
18 Correct 32 ms 85592 KB Output is correct
19 Correct 35 ms 85584 KB Output is correct
20 Correct 33 ms 85696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 85588 KB Output is correct
2 Correct 36 ms 85636 KB Output is correct
3 Correct 34 ms 85664 KB Output is correct
4 Correct 35 ms 85588 KB Output is correct
5 Correct 35 ms 85588 KB Output is correct
6 Correct 35 ms 85736 KB Output is correct
7 Correct 34 ms 85592 KB Output is correct
8 Correct 32 ms 85780 KB Output is correct
9 Correct 36 ms 85572 KB Output is correct
10 Correct 34 ms 85616 KB Output is correct
11 Correct 38 ms 85764 KB Output is correct
12 Correct 35 ms 85564 KB Output is correct
13 Correct 35 ms 85584 KB Output is correct
14 Correct 36 ms 85588 KB Output is correct
15 Correct 35 ms 85588 KB Output is correct
16 Correct 34 ms 85616 KB Output is correct
17 Correct 32 ms 85588 KB Output is correct
18 Correct 34 ms 85584 KB Output is correct
19 Correct 34 ms 85584 KB Output is correct
20 Correct 34 ms 85592 KB Output is correct
21 Correct 35 ms 85588 KB Output is correct
22 Correct 37 ms 85652 KB Output is correct
23 Correct 34 ms 85584 KB Output is correct
24 Correct 34 ms 85616 KB Output is correct
25 Correct 34 ms 85596 KB Output is correct
26 Correct 36 ms 85604 KB Output is correct
27 Correct 35 ms 85748 KB Output is correct
28 Correct 37 ms 85596 KB Output is correct
29 Correct 34 ms 85600 KB Output is correct
30 Correct 33 ms 85724 KB Output is correct
31 Correct 34 ms 85580 KB Output is correct
32 Correct 33 ms 85588 KB Output is correct
33 Correct 36 ms 85584 KB Output is correct
34 Correct 35 ms 85584 KB Output is correct
35 Correct 33 ms 85596 KB Output is correct
36 Correct 32 ms 85592 KB Output is correct
37 Correct 35 ms 85584 KB Output is correct
38 Correct 33 ms 85696 KB Output is correct
39 Correct 35 ms 85588 KB Output is correct
40 Correct 35 ms 85748 KB Output is correct
41 Correct 37 ms 85696 KB Output is correct
42 Correct 35 ms 85596 KB Output is correct
43 Correct 34 ms 85568 KB Output is correct
44 Correct 36 ms 85584 KB Output is correct
45 Correct 33 ms 85588 KB Output is correct
46 Correct 42 ms 85588 KB Output is correct
47 Correct 35 ms 85584 KB Output is correct
48 Correct 33 ms 85596 KB Output is correct
49 Correct 35 ms 85584 KB Output is correct
50 Correct 33 ms 85584 KB Output is correct
51 Correct 35 ms 85596 KB Output is correct
52 Correct 33 ms 85592 KB Output is correct
53 Correct 42 ms 85588 KB Output is correct
54 Correct 37 ms 85588 KB Output is correct
55 Correct 34 ms 85584 KB Output is correct
56 Correct 36 ms 85584 KB Output is correct
57 Correct 37 ms 85584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 85588 KB Output is correct
2 Correct 36 ms 85636 KB Output is correct
3 Correct 34 ms 85664 KB Output is correct
4 Correct 35 ms 85588 KB Output is correct
5 Correct 35 ms 85588 KB Output is correct
6 Correct 35 ms 85736 KB Output is correct
7 Correct 34 ms 85592 KB Output is correct
8 Correct 32 ms 85780 KB Output is correct
9 Correct 36 ms 85572 KB Output is correct
10 Correct 34 ms 85616 KB Output is correct
11 Correct 38 ms 85764 KB Output is correct
12 Correct 35 ms 85564 KB Output is correct
13 Correct 35 ms 85584 KB Output is correct
14 Correct 36 ms 85588 KB Output is correct
15 Correct 35 ms 85588 KB Output is correct
16 Correct 34 ms 85616 KB Output is correct
17 Correct 32 ms 85588 KB Output is correct
18 Correct 34 ms 85584 KB Output is correct
19 Correct 34 ms 85584 KB Output is correct
20 Correct 34 ms 85592 KB Output is correct
21 Correct 35 ms 85588 KB Output is correct
22 Correct 37 ms 85652 KB Output is correct
23 Correct 34 ms 85584 KB Output is correct
24 Correct 34 ms 85616 KB Output is correct
25 Correct 34 ms 85596 KB Output is correct
26 Correct 36 ms 85604 KB Output is correct
27 Correct 35 ms 85748 KB Output is correct
28 Correct 37 ms 85596 KB Output is correct
29 Correct 34 ms 85600 KB Output is correct
30 Correct 33 ms 85724 KB Output is correct
31 Correct 34 ms 85580 KB Output is correct
32 Correct 33 ms 85588 KB Output is correct
33 Correct 36 ms 85584 KB Output is correct
34 Correct 35 ms 85584 KB Output is correct
35 Correct 33 ms 85596 KB Output is correct
36 Correct 32 ms 85592 KB Output is correct
37 Correct 35 ms 85584 KB Output is correct
38 Correct 33 ms 85696 KB Output is correct
39 Correct 35 ms 85588 KB Output is correct
40 Correct 35 ms 85748 KB Output is correct
41 Correct 37 ms 85696 KB Output is correct
42 Correct 35 ms 85596 KB Output is correct
43 Correct 34 ms 85568 KB Output is correct
44 Correct 36 ms 85584 KB Output is correct
45 Correct 33 ms 85588 KB Output is correct
46 Correct 42 ms 85588 KB Output is correct
47 Correct 35 ms 85584 KB Output is correct
48 Correct 33 ms 85596 KB Output is correct
49 Correct 35 ms 85584 KB Output is correct
50 Correct 33 ms 85584 KB Output is correct
51 Correct 35 ms 85596 KB Output is correct
52 Correct 33 ms 85592 KB Output is correct
53 Correct 42 ms 85588 KB Output is correct
54 Correct 37 ms 85588 KB Output is correct
55 Correct 34 ms 85584 KB Output is correct
56 Correct 36 ms 85584 KB Output is correct
57 Correct 37 ms 85584 KB Output is correct
58 Execution timed out 1044 ms 86608 KB Time limit exceeded
59 Halted 0 ms 0 KB -