# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
855421 | vjudge1 | 수열 (APIO14_sequence) | C++17 | 118 ms | 26228 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
using namespace std;
using lol= long long int;
typedef long long ll;
typedef long double ld;
typedef long long unsigned lli;
// #define _MAXM 16000
#define cl clear
#define int ll
#define db double
#define pb push_back
#define ers erase
#define ds resize
#define W INT_MIN
#define mp make_pair
#define pll pair< long , long >
#define pii pair<ll, ll>
#define bc back()
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
#define doc (clock() * 1.0 / CLOCKS_PER_SEC) < 1.0
#define all(v) v.begin(),v.end()
const int MAX = 100 + 5;
const int LOG = 18;
const ll INF = 1e18;
const ll inf = 1e18;
const int maxn = 1e5+5;
const double me = 1e-9;
const double PI=acos(-1.0);
const int M= 1e6;
const int mod = 998244353;
const int mxn=2e5+3;
const int MAXA = 1e6 + 10;
const int MOD = 1e9 + 7;
const int DN = 4008;
const int N = 1000 + 5;
int n, k;
int dp[N][N];
int opt[N][N];
vector< int > ps(N);
int go(int i , int j){
if(j > k+ 1){
return -INF;
}
if(i == n + 1){
if(j < k + 1){
return -INF;
}
return 0;
}
if(dp[i][j] != -1){
return dp[i][j];
}
int ans = -INF;
int ind;
for(int k = i; k <= n; k++){
int cur = go(k + 1, j + 1) + (ps[k] - ps[i - 1]) * (ps[n] - ps[k]);
if(cur > ans){
ans = cur;
ind = k + 1;
}
}
opt[i][j] = ind;
return dp[i][j] = ans;
}
void kick(){
cin >> n >> k;
vector< int > a(n + 5);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){
ps[i] = ps[i - 1] + a[i];
}
memset(dp, -1 ,sizeof dp);
cout << go(1,0) << '\n';
int curi = 1 ;
int curj = 0;
while(true){
curi = opt[curi][curj];
curj++;
if(curi == n + 1){
break;
}
cout << curi - 1 << " ";
}
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.in", "r" ,stdin);
freopen("output.in", "w", stdout);
#endif
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int T = 1;
// cin >> T;
// cout.flush();
while(T--){
kick();
}
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... |