# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
569012 | Ronin13 | 수열 (APIO14_sequence) | C++14 | 2073 ms | 131072 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;
ll dp[100001][201];
ll p[100001][201];
const ll linf = 1e18 + 1;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int k; cin >> k;
ll pref[n + 1];
ll a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= k; j++) dp[i][j] = -linf;
}
dp[0][0] = 0;
pref[0] = 0;
for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
for(int i = 1; i <= n; i++){
for(int j = 0; j < k; j++){
for(int l = 0; l < i; l++){
ll val = dp[l][j] + (pref[i] - pref[l]) * (pref[n] - pref[i]);
if(dp[i][j + 1] < val){
dp[i][j + 1] = val;
p[i][j + 1] = l;
}
}
}
}
ll ans = -1;
ll mxi;
for(int i = 1; i <= n; i++){
if(ans < dp[i][k]) ans = dp[i][k], mxi = i;
}
cout << ans << "\n";
int cnt = k;
vector <int> vec;
while(cnt){
vec.pb(mxi);
mxi = p[mxi][cnt];
cnt--;
}
reverse(vec.begin(), vec.end());
for(auto to : vec) cout << to << ' ';
return 0;
}
컴파일 시 표준 에러 (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... |