이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define S second
#define F first
//const int inf = 1e18;
const int N = 100005;
const ll inf = 1e18;
int n, y, k, par[N][205], k1, ind;
ll a[N], b[N], pref[N], suma, dp[N][205];
bool cut[N][205], used[N];
vector<int> ans;
ll f(int i, int j, int m){
if(dp[m][j - 1] == -inf) return -inf;
// cout << i << ' ' << j << ' ' << m << '\n';
// cout << dp[m][j - 1] << ' ' << (pref[i] - pref[m]) << ' ' << (pref[n] - pref[i]) << '\n';
return dp[m][j - 1] + (pref[i] - pref[m]) * (pref[n] - pref[i]);
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
k1 = k;
k++;
dp[0][k] = -1;
for(int i = 1; i <= n; ++i){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
for(int i = 0; i <= n; ++i){
for(int j = 2; j <= k; ++j){
dp[i][j] = -inf;
}
}
for(int i = 1; i <= n; ++i){
for(int j = 2; j <= min(i + 1, k); ++j){
// cout << "_____________\n\n";
for(int l = 0; l < i; ++l){
if(f(i, j, l) > dp[i][j]){
dp[i][j] = max(dp[i][j], f(i, j, l));
par[i][j] = l;
}
}
// cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
}
if(dp[i][k] > dp[ind][k]){
ind = i;
}
}
cout << dp[ind][k] << '\n';
// while(dp[ind - 1][k] == dp[ind][k]) ind--;
// cout << ind << '\n';
while(ind != 0){
ans.pb(ind);
ind = par[ind][k];
k--;
}
reverse(ans.begin(), ans.end());
for(auto to : ans){
cout << to << ' ';
}
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp:27:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main(){
| ^~~~
# | 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... |