# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
489586 | 2021-11-23T10:08:49 Z | ssense | 수열 (APIO14_sequence) | C++14 | 362 ms | 7200 KB |
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI (ld)2*acos(0.0) #define nax 200005 #define pb push_back #define sc second #define fr first #define int long long #define endl '\n' #define ld long double #define NO cout << "NO" << endl #define YES cout << "YES" << endl int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//ssense int dp[1005][205]; int par[1005][205]; void solve() { int n, k; cin >> n >> k; vint a = read(n); prefix_sum pref; pref.build(a); for(int i = 1; i < n; i++) { dp[i][1] = pref.get(1, i)*pref.get(i+1, n); } for(int i = 2; i < n; i++) { for(int nowk = 1; nowk <= k; nowk++) { for(int t = 1; t < i; t++) { if(dp[t][nowk-1]+pref.get(t+1, i)*pref.get(i+1, n) >= dp[i][nowk]) { par[i][nowk] = t; dp[i][nowk] = max(dp[i][nowk], dp[t][nowk-1]+pref.get(t+1, i)*pref.get(i+1, n)); } } } } int ans = 0; int best = 0; for(int i = 1; i < n; i++) { if(ans < dp[i][k]) { best = i; } ans = max(ans, dp[i][k]); } vint ind; int nowind = best; int nowmove = k; while(nowind != 0) { ind.pb(nowind); nowind = par[nowind][nowmove]; nowmove--; } cout << ans << endl; reverse(all(ind)); for(auto x : ind) { cout << x << " "; } cout << endl; } int32_t main(){ startt int t = 1; //cin >> t; while (t--) { solve(); } } /* 7 3 4 1 3 4 0 2 3 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | contestant found the optimal answer: 108 == 108 |
2 | Correct | 1 ms | 332 KB | contestant found the optimal answer: 999 == 999 |
3 | Incorrect | 0 ms | 332 KB | Unexpected end of file - int32 expected |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 460 KB | contestant found the optimal answer: 1093956 == 1093956 |
2 | Correct | 1 ms | 460 KB | contestant found the optimal answer: 302460000 == 302460000 |
3 | Correct | 1 ms | 444 KB | contestant found the optimal answer: 122453454361 == 122453454361 |
4 | Correct | 1 ms | 448 KB | contestant found the optimal answer: 93663683509 == 93663683509 |
5 | Correct | 1 ms | 444 KB | contestant found the optimal answer: 1005304678 == 1005304678 |
6 | Correct | 1 ms | 460 KB | contestant found the optimal answer: 933702 == 933702 |
7 | Correct | 1 ms | 452 KB | contestant found the optimal answer: 25082842857 == 25082842857 |
8 | Incorrect | 1 ms | 460 KB | declared answer doesn't correspond to the split scheme: declared = 687136, real = 678115 |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 844 KB | contestant found the optimal answer: 610590000 == 610590000 |
2 | Correct | 1 ms | 972 KB | contestant found the optimal answer: 311760000 == 311760000 |
3 | Correct | 15 ms | 964 KB | contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 | Correct | 1 ms | 972 KB | contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 | Correct | 11 ms | 892 KB | contestant found the optimal answer: 1019625819 == 1019625819 |
6 | Correct | 14 ms | 908 KB | contestant found the optimal answer: 107630884 == 107630884 |
7 | Correct | 16 ms | 972 KB | contestant found the optimal answer: 475357671774 == 475357671774 |
8 | Incorrect | 4 ms | 972 KB | declared answer doesn't correspond to the split scheme: declared = 193556962, real = 193400941 |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 3532 KB | contestant found the optimal answer: 21503404 == 21503404 |
2 | Correct | 4 ms | 3536 KB | contestant found the optimal answer: 140412195 == 140412195 |
3 | Correct | 362 ms | 3488 KB | contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 | Correct | 5 ms | 3532 KB | contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 | Correct | 348 ms | 3540 KB | contestant found the optimal answer: 679388326 == 679388326 |
6 | Correct | 298 ms | 3456 KB | contestant found the optimal answer: 4699030287 == 4699030287 |
7 | Correct | 349 ms | 3500 KB | contestant found the optimal answer: 12418819758185 == 12418819758185 |
8 | Incorrect | 345 ms | 3572 KB | declared answer doesn't correspond to the split scheme: declared = 31093317350, real = 31091859600 |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 4428 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 10 ms | 7200 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |