답안 #166628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166628 2019-12-03T08:29:55 Z abil K개의 묶음 (IZhO14_blocks) C++14
53 / 100
1000 ms 4600 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int a[N], dp[1012][1012], table[20][1012], n, l[N];

void build(){
	for(int i = 2;i <= n; i++){
		l[i] = l[i / 2] + 1;
	}
	
	for(int i = 1;i <= n; i++){
		table[0][i] = a[i];
	}
	for(int i = 1;i <= l[n]; i++){
		for(int j = 1;j <= n; j++){
			table[i][j] = max(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
		}
	}
}

int get(int left,int right){
	int logg = l[right - left + 1];
	return max(table[logg][left], table[logg][right - (1 << logg) + 1]);
}
main()
{
	int k;
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n; i++){
		scanf("%d", &a[i]);
	}
	build();
	memset(dp, 0x3f3f3f3f,sizeof(dp));
	for(int i = 1;i <= n; i++){
		dp[1][i] = get(1, i);
	}
	for(int i = 2;i <= k; i++){
		for(int j = i;j <= n; j++){
			for(int p = j;p <= n; p++){
				dp[i][p] = min(dp[i][p], dp[i - 1][j - 1] + get(j, p));
			}
		}
	}
	cout << dp[k][n];
}

Compilation message

blocks.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Correct 5 ms 4344 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 6 ms 4344 KB Output is correct
5 Correct 5 ms 4344 KB Output is correct
6 Correct 5 ms 4344 KB Output is correct
7 Correct 6 ms 4344 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 5 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 6 ms 4348 KB Output is correct
12 Correct 6 ms 4344 KB Output is correct
13 Correct 5 ms 4344 KB Output is correct
14 Correct 5 ms 4344 KB Output is correct
15 Correct 6 ms 4344 KB Output is correct
16 Correct 6 ms 4344 KB Output is correct
17 Correct 5 ms 4344 KB Output is correct
18 Correct 6 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Correct 5 ms 4344 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 5 ms 4344 KB Output is correct
5 Correct 6 ms 4348 KB Output is correct
6 Correct 5 ms 4344 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 5 ms 4344 KB Output is correct
9 Correct 5 ms 4348 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 6 ms 4316 KB Output is correct
12 Correct 7 ms 4344 KB Output is correct
13 Correct 5 ms 4344 KB Output is correct
14 Correct 6 ms 4344 KB Output is correct
15 Correct 6 ms 4344 KB Output is correct
16 Correct 6 ms 4344 KB Output is correct
17 Correct 6 ms 4344 KB Output is correct
18 Correct 6 ms 4344 KB Output is correct
19 Correct 6 ms 4344 KB Output is correct
20 Correct 6 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4344 KB Output is correct
2 Correct 6 ms 4344 KB Output is correct
3 Correct 5 ms 4344 KB Output is correct
4 Correct 5 ms 4344 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 6 ms 4348 KB Output is correct
9 Correct 6 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 6 ms 4344 KB Output is correct
12 Correct 6 ms 4344 KB Output is correct
13 Correct 6 ms 4344 KB Output is correct
14 Correct 6 ms 4348 KB Output is correct
15 Correct 7 ms 4344 KB Output is correct
16 Correct 7 ms 4344 KB Output is correct
17 Correct 6 ms 4344 KB Output is correct
18 Correct 11 ms 4344 KB Output is correct
19 Correct 7 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 4600 KB Time limit exceeded
2 Halted 0 ms 0 KB -