Submission #498317

#TimeUsernameProblemLanguageResultExecution timeMemory
498317mansurSplit the sequence (APIO14_sequence)C++17
0 / 100
2 ms372 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; } 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++) { vector<pii> h; val1 += a[j]; val2 -= a[j]; for (int s = 0; s < sz(sg); s++) { if (s == i) { h.pb({sg[s].ff, j}); h.pb({j + 1, sg[s].ss}); }else h.pb(sg[s]); } cur.pb(j); f(h, cnt + 1, sum + val1 * val2); 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:46: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]
   46 |  for (int i = 0; i < sz(sg); i++) {
      |                    ^
sequence.cpp:53:22: 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]
   53 |    for (int s = 0; s < sz(sg); s++) {
      |                      ^
sequence.cpp: At global scope:
sequence.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main() {
      | ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:67:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |  freopen("sequence.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:68:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  freopen("sequence.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...