Submission #231974

#TimeUsernameProblemLanguageResultExecution timeMemory
231974AM1648Split the sequence (APIO14_sequence)C++17
100 / 100
1081 ms81252 KiB
/* be name khoda */ // #define long_enable #include <iostream> #include <algorithm> #include <cstring> #include <numeric> #include <vector> #include <fstream> #include <set> #include <map> using namespace std; #ifdef long_enable typedef long long int ll; #else typedef int ll; #endif typedef pair<ll, ll> pii; typedef pair<pii, ll> ppi; typedef pair<ll, pii> pip; typedef vector<ll> vi; typedef vector<pii> vpii; #define forifrom(i, s, n) for (ll i = s; i < n; ++i) #define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i) #define fori(i, n) forifrom (i, 0, n) #define forir(i, n) forirto (i, n, 0) #define F first #define S second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define smin(a, b) a = min(a, (b)) #define smax(a, b) a = max(a, (b)) #define debug(x) cout << #x << " -> " << (x) << endl #define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl #define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl #define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl #define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl #define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl #define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl #define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl #define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl #define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl const ll MOD = 1000000007; const ll INF = 2000000000; const long long BIG = 1446803456761533460LL; #define Add(a, b) a = ((a) + (b)) % MOD #define Mul(a, b) a = (1LL * (a) * (b)) % MOD // ----------------------------------------------------------------------- const ll maxn = 100010; const ll maxk = 210; ll n, k, A[maxn], ps[maxn]; long long dp[2][maxn]; ll dpi[maxk][maxn]; void solve(ll l, ll r, ll ul, ll ur, ll j) { if (l >= r) return; ll mid = (l + r) / 2; dp[j & 1][mid] = BIG; forifrom (i, ul, ur) { long long v = ps[mid] - ps[i]; if (dp[j & 1 ^ 1][i] + v * v <= dp[j & 1][mid]) { dpi[j][mid] = i; dp[j & 1][mid] = dp[j & 1 ^ 1][i] + v * v; } } solve(l, mid, ul, dpi[j][mid] + 1, j); solve(mid + 1, r, dpi[j][mid], ur, j); } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); // ifstream cin("sequence.in"); cin >> n >> k; fori (i, n) cin >> A[i]; fori (i, n) ps[i + 1] = ps[i] + A[i]; fori (i, n) dp[0][i + 1] = 1LL * ps[i + 1] * ps[i + 1]; fori (j, k) solve(0, n + 1, 0, n + 1, j + 1); long long ans = (1LL * ps[n] * ps[n] - dp[k & 1][n]) / 2; cout << ans << '\n'; ll x = n; forir (i, k) { x = x <= dpi[i + 1][x] ? x - 1 : dpi[i + 1][x]; cout << x << ' '; } cout << '\n'; }

Compilation message (stderr)

sequence.cpp: In function 'void solve(ll, ll, ll, ll, ll)':
sequence.cpp:72:18: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         if (dp[j & 1 ^ 1][i] + v * v <= dp[j & 1][mid]) {
                ~~^~~
sequence.cpp:74:35: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             dp[j & 1][mid] = dp[j & 1 ^ 1][i] + v * v;
                                 ~~^~~
#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...