이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define blank " "
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<ll, ll> pll;
const int MAXN = 100100;
const int MOD = 1e9+7;
struct Line {
ll a, b; double c; int t;
};
double cross(Line x, Line y) { return (double)(y.b-x.b)/(x.a-y.a); }
ll sum[MAXN], dp[MAXN][220];
int idx[MAXN][220];
vector<Line> v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
for(int i = 1; i <= n; i++) {
int a; cin >> a;
sum[i] = sum[i-1] + a;
}
for(int i = 1; i <= n; i++) dp[i][1] = sum[i]*sum[i];
for(int j = 2; j <= k+1; j++) {
int piv = 0;
v.clear();
for(int i = j; i <= n; i++) {
Line g = {-2*sum[i-1], sum[i-1]*sum[i-1]+dp[i-1][j-1], 0, i-1};
while(v.size() && (g.c = cross(*v.rbegin(), g)) < v.rbegin()->c) v.pop_back();
v.push_back(g);
while(piv+1 < v.size() && v[piv+1].c < sum[i]) piv++;
dp[i][j] = sum[i]*sum[i] + v[piv].a*sum[i] + v[piv].b;
idx[i][j] = v[piv].t;
}
}
cout << (sum[n]*sum[n] - dp[n][k+1])/2 << endl;
for(int i = idx[n][k+1]; k; i = idx[i][k--]) cout << i << blank;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:45:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while(piv+1 < v.size() && v[piv+1].c < sum[i]) piv++;
| ~~~~~~^~~~~~~~~~
# | 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... |