Submission #635869

#TimeUsernameProblemLanguageResultExecution timeMemory
635869ghostwriterSplit the sequence (APIO14_sequence)C++14
33 / 100
7 ms1516 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const ll oo = 2e18 + 5;
const int N = 1005;
const int K = 205;
int n, k, a[N], s, f[N], pre[N][K];
ll d[K][N];
ll func(int a, int b) { return 1LL * (a - b) * (s - a + b); }
void trace(int i, int j) {
	int prev = pre[i][j];
	if (!prev) return;
	cout << prev << ' ';
	trace(i - 1, prev);
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen("BRUTE.out", "w", stdout);
    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    FOR(i, 1, n) f[i] = f[i - 1] + a[i];
    s = f[n];
    FOR(i, 1, n) d[0][i] = -oo;
    FOR(i, 1, k + 1)
	FOR(j, 0, n) {
		d[i][j] = -oo;
		FOR(z, 0, j - 1) {
			ll tmp = d[i - 1][z] + func(f[j], f[z]);
			if (d[i][j] < tmp) {
				d[i][j] = tmp;
				pre[i][j] = z;
			}
		}
	}
	cout << d[k + 1][n] / 2 << '\n';
	trace(k + 1, n);
    return 0;
}

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sequence.cpp:53:5: note: in expansion of macro 'FOR'
   53 |     FOR(i, 1, n) cin >> a[i];
      |     ^~~
sequence.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sequence.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(i, 1, n) f[i] = f[i - 1] + a[i];
      |     ^~~
sequence.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sequence.cpp:56:5: note: in expansion of macro 'FOR'
   56 |     FOR(i, 1, n) d[0][i] = -oo;
      |     ^~~
sequence.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sequence.cpp:57:5: note: in expansion of macro 'FOR'
   57 |     FOR(i, 1, k + 1)
      |     ^~~
sequence.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sequence.cpp:58:2: note: in expansion of macro 'FOR'
   58 |  FOR(j, 0, n) {
      |  ^~~
sequence.cpp:24:31: warning: unnecessary parentheses in declaration of 'z' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
sequence.cpp:60:3: note: in expansion of macro 'FOR'
   60 |   FOR(z, 0, j - 1) {
      |   ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...