이 제출은 이전 버전의 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 ll inf = (ll)1e9 + 7;
const int N = (int)1e5 + 2;
int n,k,id;
int a[N],pr[201][N],o;
int p[N];
ll mx;
ll dp[2][N];
ll calc (int r,int l) {
return (p[r] - p[l]) * 1ll * (p[n] - p[r]);
}
void compute (int k,int l,int r,int L,int R) {
if (l > r)
return;
int m = (l + r) >> 1;
for (int i = L; i <= min(m,R); i ++) {
ll now = dp[(k - 1) & 1][i - 1] + calc(m,i - 1);
if (now >= dp[k & 1][m])
dp[k & 1][m] = now,pr[k][m] = i;
}
if (mx <= dp[k & 1][m] && m != n)
mx = dp[k & 1][m],id = m;
compute (k,l,m - 1,L,pr[k][m]);
compute (k,m + 1,r,pr[k][m],R);
}
int main () {
scanf ("%d%d", &n,&k);
o = k;
for (int i = 1; i <= n; i ++) {
scanf ("%d", &a[i]);
p[i] = p[i - 1] + a[i];
}
for (int i = 1; i <= k; i ++)
compute (i,i,n,i,n - 1);
printf("%lld\n", mx);
deque<int> dq;
while (id > 0 && k > 0) {
cout << id << " ";
id = pr[k][id] - 1;
k --;
}
}
/**
7 3
4 1 3 4 0 2 3
**/
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:44:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n,&k);
^
sequence.cpp:49: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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |