Submission #848732

#TimeUsernameProblemLanguageResultExecution timeMemory
848732lbadea1000Split the sequence (APIO14_sequence)C++17
0 / 100
1 ms556 KiB
#include <bits/stdc++.h> using namespace std; const int NMAX = 1e5; int v[NMAX], sp[NMAX]; vector<int> split_points; int sum(int l, int r) { if(l == 0) return sp[r]; return sp[r] - sp[l - 1]; } int main() { int n, k; FILE *fin, *fout; fin = fopen("sequence.in", "r"); fout = fopen("sequence.out", "w"); fscanf(fin, "%d%d", &n, &k); for(int i = 0; i < n; i++) fscanf(fin, "%d", &v[i]); sp[0] = v[0]; for(int i = 1; i < n; i++) sp[i] = sp[i - 1] + v[i]; long long ans = 0; int kk = k; while(kk--) { int first = -1, end; int ind = 0; long long maxx = 0, pozmax = 0; if(split_points.size() == 0) end = n - 1; else end = split_points[0]; for(int i = 0; i < n; i++) { if(ind < split_points.size() && i == split_points[ind]) { first = split_points[ind]; ind++; if(ind == split_points.size()) end = n - 1; else end = split_points[ind]; } else { // (first, i] cu [i + 1, end] //cout << i << ' ' << first << ' ' << end << endl; long long val = 1LL * sum(first + 1, i) * sum(i + 1, end); if(val >= maxx) { maxx = val; pozmax = i; } } } //cout << maxx << ' ' << pozmax << endl; ans += maxx; split_points.push_back(pozmax); sort(split_points.begin(), split_points.end()); } fprintf(fout, "%lld\n", ans); //cout << ans << ' ' << k << endl; for(int i = 0; i < k; i++) fprintf(fout, "%d ", split_points[i] + 1); fclose(fin); fclose(fout); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             if(ind < split_points.size() && i == split_points[ind]) {
      |                ~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:40:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 if(ind == split_points.size())
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:20:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     fscanf(fin, "%d%d", &n, &k);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:22:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         fscanf(fin, "%d", &v[i]);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~
#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...