Submission #489580

# Submission time Handle Problem Language Result Execution time Memory
489580 2021-11-23T09:57:27 Z ssense Split the sequence (APIO14_sequence) C++14
0 / 100
17 ms 10588 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);
	dp[1][1] = a[0]*pref.get(2, 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

sequence.cpp: In member function 'void prefix_sum::build(std::vector<long long int>)':
sequence.cpp:21:699: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |                                 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
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB contestant found the optimal answer: 108 == 108
2 Incorrect 0 ms 332 KB declared answer doesn't correspond to the split scheme: declared = 965, real = 734
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 460 KB contestant didn't find the optimal answer: 1093123 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 972 KB declared answer doesn't correspond to the split scheme: declared = 610500000, real = 510621050
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3520 KB declared answer doesn't correspond to the split scheme: declared = 21458040, real = 14796084
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 7756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 10588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -