이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
const int inf = (int)1e9 + 7;
const int N = (int)1e5 + 2;
int n,kk;
int dp[2][N];
int a[N];
int t[21][N];
void buildtable() {
for (int i = 0; i <= log2(n); i ++) {
for (int j = 1; j <= n; j ++) {
if (i == 0) {
t[i][j] = a[j];
continue;
}
t[i][j] = max(t[i - 1][j],t[i - 1][j + (1 << (i - 1))]);
}
}
}
int get (int l,int r) {
int cur = log2(r - l + 1);
return max(t[cur][l],t[cur][r - (1 << cur) + 1]);
}
void compute (int k,int l,int r,int L,int R) {
if (l > r)
return;
int m = (r + l) / 2;
int opt = L;
int &d = dp[k][m];
for (int i = L; i <= min(m,R); i ++) {
int now = dp[k ^ 1][i - 1] + get(i,m);
if (now < d)
d = now,opt = i;
}
compute (k,l,m - 1,L,opt);
compute (k,m + 1,r,opt,R);
}
main () {
scanf ("%d%d", &n,&kk);
for (int i = 1; i <= n; i ++)
scanf ("%d", &a[i]);
memset(dp,0x3f3f3f3f,sizeof(dp));
buildtable();
for (int i = 1; i <= n; i ++)
dp[1][i] = get(1,i);
for (int i = 2; i <= kk; i ++)
compute (i & 1,i,n,i,n);
cout << dp[kk & 1][n] << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
blocks.cpp:53:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
blocks.cpp: In function 'int main()':
blocks.cpp:54:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n,&kk);
^
blocks.cpp:57:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &a[i]);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |