Submission #1101404

# Submission time Handle Problem Language Result Execution time Memory
1101404 2024-10-16T08:12:50 Z quocthang K blocks (IZhO14_blocks) C++14
53 / 100
16 ms 17024 KB
#include <bits/stdc++.h>
#define base 31
#define fi first
#define endl "\n"
#define se second
#define NAME "FILE"
#define ll long long
//#define int long long
#define mod 1000000007
#define pii pair<int,int>
#define bit(mask,i) (mask&(1<<i))
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define turn_on(mask,i) (mask|(1<<i))
#define turn_off(mask,i) (mask^(1<<i))

template <class T1, class T2>
bool maximize(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}

template <class T1, class T2>
bool minimize(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}

template <class T1, class T2>
void add(T1 &a, T2 b){a += b; if (a >= mod) a -= mod;}

template <class T1, class T2>
void sub(T1 &a, T2 b){a -= b; if (a < 0) a += mod;}

using namespace std;
int n,k,dp[1010][1010],a[100010]; 
int mx[100010][20];
int get(int l,int r){
	int k=__lg(r-l+1);
	return max(mx[l][k],mx[r-(1<<k)+1][k]);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	if (fopen(NAME".inp","r")){
		freopen(NAME".inp","r",stdin);
		freopen(NAME".out","w",stdout);
	}
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i],mx[i][0]=a[i];
	for(int j=1;(1<<j)<=n;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
		}
	}
	memset(dp,0x3f,sizeof dp);
	dp[0][0]=0;
	for(int j=1;j<=k;j++){
		for(int i=1;i<=n;i++){
			for(int k=1;k<=i;k++){
				minimize(dp[i][j],dp[k-1][j-1]+get(k,i));
			}
		}
	}
	cout<<dp[n][k];
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:39:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   freopen(NAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   freopen(NAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6396 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6224 KB Output is correct
6 Correct 2 ms 6396 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Correct 2 ms 6208 KB Output is correct
9 Correct 2 ms 6224 KB Output is correct
10 Correct 2 ms 6224 KB Output is correct
11 Correct 2 ms 6180 KB Output is correct
12 Correct 2 ms 6224 KB Output is correct
13 Correct 2 ms 6096 KB Output is correct
14 Correct 3 ms 6224 KB Output is correct
15 Correct 2 ms 6224 KB Output is correct
16 Correct 2 ms 6224 KB Output is correct
17 Correct 2 ms 6224 KB Output is correct
18 Correct 3 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6224 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6392 KB Output is correct
6 Correct 2 ms 6212 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Correct 2 ms 6224 KB Output is correct
9 Correct 3 ms 6224 KB Output is correct
10 Correct 2 ms 6224 KB Output is correct
11 Correct 2 ms 6224 KB Output is correct
12 Correct 2 ms 6224 KB Output is correct
13 Correct 2 ms 6224 KB Output is correct
14 Correct 3 ms 6124 KB Output is correct
15 Correct 2 ms 6224 KB Output is correct
16 Correct 2 ms 6224 KB Output is correct
17 Correct 2 ms 6224 KB Output is correct
18 Correct 2 ms 6224 KB Output is correct
19 Correct 2 ms 6224 KB Output is correct
20 Correct 2 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6396 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6224 KB Output is correct
6 Correct 2 ms 6396 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Correct 2 ms 6208 KB Output is correct
9 Correct 2 ms 6224 KB Output is correct
10 Correct 2 ms 6224 KB Output is correct
11 Correct 2 ms 6180 KB Output is correct
12 Correct 2 ms 6224 KB Output is correct
13 Correct 2 ms 6096 KB Output is correct
14 Correct 3 ms 6224 KB Output is correct
15 Correct 2 ms 6224 KB Output is correct
16 Correct 2 ms 6224 KB Output is correct
17 Correct 2 ms 6224 KB Output is correct
18 Correct 3 ms 6224 KB Output is correct
19 Correct 2 ms 6224 KB Output is correct
20 Correct 2 ms 6224 KB Output is correct
21 Correct 2 ms 6224 KB Output is correct
22 Correct 2 ms 6224 KB Output is correct
23 Correct 2 ms 6392 KB Output is correct
24 Correct 2 ms 6212 KB Output is correct
25 Correct 2 ms 6224 KB Output is correct
26 Correct 2 ms 6224 KB Output is correct
27 Correct 3 ms 6224 KB Output is correct
28 Correct 2 ms 6224 KB Output is correct
29 Correct 2 ms 6224 KB Output is correct
30 Correct 2 ms 6224 KB Output is correct
31 Correct 2 ms 6224 KB Output is correct
32 Correct 3 ms 6124 KB Output is correct
33 Correct 2 ms 6224 KB Output is correct
34 Correct 2 ms 6224 KB Output is correct
35 Correct 2 ms 6224 KB Output is correct
36 Correct 2 ms 6224 KB Output is correct
37 Correct 2 ms 6224 KB Output is correct
38 Correct 2 ms 6224 KB Output is correct
39 Correct 3 ms 6392 KB Output is correct
40 Correct 2 ms 6224 KB Output is correct
41 Correct 2 ms 6224 KB Output is correct
42 Correct 2 ms 6224 KB Output is correct
43 Correct 2 ms 6224 KB Output is correct
44 Correct 2 ms 6224 KB Output is correct
45 Correct 2 ms 6224 KB Output is correct
46 Correct 2 ms 6224 KB Output is correct
47 Correct 2 ms 6392 KB Output is correct
48 Correct 3 ms 6224 KB Output is correct
49 Correct 2 ms 6392 KB Output is correct
50 Correct 2 ms 6224 KB Output is correct
51 Correct 2 ms 6108 KB Output is correct
52 Correct 3 ms 6392 KB Output is correct
53 Correct 4 ms 6224 KB Output is correct
54 Correct 4 ms 6224 KB Output is correct
55 Correct 3 ms 6224 KB Output is correct
56 Correct 4 ms 6224 KB Output is correct
57 Correct 4 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6396 KB Output is correct
2 Correct 2 ms 6224 KB Output is correct
3 Correct 2 ms 6224 KB Output is correct
4 Correct 2 ms 6224 KB Output is correct
5 Correct 2 ms 6224 KB Output is correct
6 Correct 2 ms 6396 KB Output is correct
7 Correct 2 ms 6224 KB Output is correct
8 Correct 2 ms 6208 KB Output is correct
9 Correct 2 ms 6224 KB Output is correct
10 Correct 2 ms 6224 KB Output is correct
11 Correct 2 ms 6180 KB Output is correct
12 Correct 2 ms 6224 KB Output is correct
13 Correct 2 ms 6096 KB Output is correct
14 Correct 3 ms 6224 KB Output is correct
15 Correct 2 ms 6224 KB Output is correct
16 Correct 2 ms 6224 KB Output is correct
17 Correct 2 ms 6224 KB Output is correct
18 Correct 3 ms 6224 KB Output is correct
19 Correct 2 ms 6224 KB Output is correct
20 Correct 2 ms 6224 KB Output is correct
21 Correct 2 ms 6224 KB Output is correct
22 Correct 2 ms 6224 KB Output is correct
23 Correct 2 ms 6392 KB Output is correct
24 Correct 2 ms 6212 KB Output is correct
25 Correct 2 ms 6224 KB Output is correct
26 Correct 2 ms 6224 KB Output is correct
27 Correct 3 ms 6224 KB Output is correct
28 Correct 2 ms 6224 KB Output is correct
29 Correct 2 ms 6224 KB Output is correct
30 Correct 2 ms 6224 KB Output is correct
31 Correct 2 ms 6224 KB Output is correct
32 Correct 3 ms 6124 KB Output is correct
33 Correct 2 ms 6224 KB Output is correct
34 Correct 2 ms 6224 KB Output is correct
35 Correct 2 ms 6224 KB Output is correct
36 Correct 2 ms 6224 KB Output is correct
37 Correct 2 ms 6224 KB Output is correct
38 Correct 2 ms 6224 KB Output is correct
39 Correct 3 ms 6392 KB Output is correct
40 Correct 2 ms 6224 KB Output is correct
41 Correct 2 ms 6224 KB Output is correct
42 Correct 2 ms 6224 KB Output is correct
43 Correct 2 ms 6224 KB Output is correct
44 Correct 2 ms 6224 KB Output is correct
45 Correct 2 ms 6224 KB Output is correct
46 Correct 2 ms 6224 KB Output is correct
47 Correct 2 ms 6392 KB Output is correct
48 Correct 3 ms 6224 KB Output is correct
49 Correct 2 ms 6392 KB Output is correct
50 Correct 2 ms 6224 KB Output is correct
51 Correct 2 ms 6108 KB Output is correct
52 Correct 3 ms 6392 KB Output is correct
53 Correct 4 ms 6224 KB Output is correct
54 Correct 4 ms 6224 KB Output is correct
55 Correct 3 ms 6224 KB Output is correct
56 Correct 4 ms 6224 KB Output is correct
57 Correct 4 ms 6224 KB Output is correct
58 Runtime error 16 ms 17024 KB Execution killed with signal 11
59 Halted 0 ms 0 KB -