Submission #930925

#TimeUsernameProblemLanguageResultExecution timeMemory
930925AtabayRajabliSplit the sequence (APIO14_sequence)C++17
0 / 100
235 ms2392 KiB
#include <bits/stdc++.h> // author : a1abay #define pb push_back #define all(v) v.begin(), v.end() #define int ll #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a*b / (__gcd(a, b))) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long ll; const int inf = 1e9 + 7; const int inff = 1e18 + 7; const int sz = 1e5 + 5; using namespace std; void open(string s, string f) { freopen((s + ".txt").c_str(), "r", stdin); freopen((f + ".txt").c_str(), "w", stdout); } int n, k, a[sz], p[sz]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // open("in", "out"); cin >> n >> k; for(int i = 1; i <= n; i++)cin >> a[i]; for(int i = 1; i <= n; i++)p[i] = p[i - 1] + a[i]; set<int> splits; splits.insert(0); splits.insert(n); int ans = 0; vector<int> cuts; while(k--) { int mx = -1, cut = -1; for(int i = 1; i <= n; i++) { auto it = splits.lower_bound(i); int l = *--it + 1, r = *++it; if(l > r)continue; int lx = p[i] - p[l - 1]; int rx = p[r] - p[i]; if(lx * rx > mx) { mx = lx * rx; cut = i; } } ans += mx; splits.insert(cut); cuts.pb(cut); } cout << ans << '\n'; for(int i : cuts)cout << i << " "; }

Compilation message (stderr)

sequence.cpp: In function 'void open(std::string, std::string)':
sequence.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s + ".txt").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen((f + ".txt").c_str(), "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...