Submission #498412

#TimeUsernameProblemLanguageResultExecution timeMemory
498412mansurSplit the sequence (APIO14_sequence)C++17
0 / 100
70 ms2508 KiB
#include<bits/stdc++.h> /* #pragma optimize ("g",on) #pragma GCC optimize ("inline") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma comment(linker, "/stack:200000000") */ //01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001 using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ll long long #define pb push_back #define sz(a) a.size() #define nl '\n' #define popb pop_back() #define ld double #define ull unsigned long long #define ff first #define ss second #define fix fixed << setprecision #define pii pair<int, int> #define E exit (0) #define int long long const int inf = 1e15, N = 3e5 + 5, mod = 998244353; vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int n, k; int a[N], mx; vector<int> cur, ans; void f(vector<pii> sg, int cnt, int sum) { if (cnt == k) { if (mx <= sum) ans = cur, mx = sum; return; } int mx = 0; pii pos; for (int i = 0; i < sz(sg); i++) { int val1 = 0, val2 = 0; for (int j = sg[i].ff; j <= sg[i].ss; j++) val2 += a[j]; for (int j = sg[i].ff; j < sg[i].ss; j++) { val1 += a[j]; val2 -= a[j]; if (val1 * val2 > mx) { mx = val1 * val2; pos = {i, j}; } } } int r = sg[pos.ff].ss; cur.pb(pos.ss); sg[pos.ff].ss = pos.ss; sg.pb({pos.ss + 1, r}); f(sg, cnt + 1, sum + mx); sg.popb; sg[pos.ff].ss = r; cur.popb; } main() { //freopen("sequence.in", "r", stdin); //freopen("sequence.out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; f({{1, n}}, 0, 0); cout << mx << nl; for (auto e: ans) cout << e << ' '; }

Compilation message (stderr)

sequence.cpp: In function 'void f(std::vector<std::pair<long long int, long long int> >, long long int, long long int)':
sequence.cpp:48:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for (int i = 0; i < sz(sg); i++) {
      |                    ^
sequence.cpp: At global scope:
sequence.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main() {
      | ^~~~
#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...