# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
135271 | Lawliet | Split the sequence (APIO14_sequence) | C++14 | 2056 ms | 86732 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAXK 210
#define MAXN 100010
#define INF 1000000000000000000LL
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
int n, k;
int v[MAXN];
int opt[MAXN][MAXK];
lli sv[MAXN];
lli dp[MAXN][2];
lli cost(int l, int c, int r)
{
lli firstPart = sv[c - 1] - sv[l - 1];
lli secondPart = sv[r] - sv[c - 1];
return firstPart*secondPart;
}
void DivAndConquer(int line)
{
queue<pii> q;
q.push({1 , n});
q.push({2 , n});
while(!q.empty())
{
int L = q.front().first;
int R = q.front().second;
q.pop();
int optmin = q.front().first;
int optmax = q.front().second;
q.pop();
if(L > R) continue;
int m = (L + R)/2;
int optInd = L;
lli optValue = -1;
for(int g = optmin ; g <= optmax && g <= m ; g++)
{
lli curAns = dp[g - 1][1 - line%2] + cost(1 , g , m);
if(curAns > optValue)
{
optInd = g;
optValue = curAns;
}
}
dp[m][line%2] = optValue;
opt[m][line] = optInd;
q.push({L , m - 1});
q.push({optmin , optInd});
q.push({m + 1 , R});
q.push({optInd , optmax});
}
}
int main()
{
scanf("%d %d",&n,&k);
for(int g = 1 ; g <= n ; g++)
{
scanf("%d",&v[g]);
sv[g] = sv[g - 1] + v[g];
}
dp[0][0] = dp[0][1] = -INF;
for(int l = 1 ; l <= k ; l++)
DivAndConquer( l );
printf("%lld\n",dp[n][k%2]);
int cur = n;
for(int g = k ; g > 0 ; g--)
{
printf("%d ",opt[cur][g] - 1);
cur = opt[cur][g] - 1;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |