Submission #161074

#TimeUsernameProblemLanguageResultExecution timeMemory
161074stoyan_malininBigger segments (IZhO19_segments)C++14
0 / 100
2 ms376 KiB
#include<iostream> #include<vector> using namespace std; const int MAXN = 5e5 + 5; int n; long long a[MAXN]; struct segment { int l, r; long long sum; segment(){} segment(int l, int r, long long sum) { this->l = l; this->r = r; this->sum = sum; } }; vector <segment> v; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int answer = 0; cin >> n; for(int i = 0;i<n;i++) { cin >> a[i]; } v.push_back(segment(0, 0, a[0])); segment curr = segment(1, 0, 0); for(int i = 1;i<n;i++) { curr.r++; curr.sum += a[i]; for(int j = v.size()-1;j>=1;j--) { while(v[j].sum - a[ v[j].l ] >= v[j-1].sum + a[ v[j].l ]) { v[j].sum -= a[ v[j].l ]; v[j-1].sum += a[ v[j].l ]; v[j].l++; v[j-1].r++; } } for(int j = 1;j<v.size();j++) { while(v[j].sum - a[ v[j].l ] >= v[j-1].sum + a[ v[j].l ]) { v[j].sum -= a[ v[j].l ]; v[j-1].sum += a[ v[j].l ]; v[j].l++; v[j-1].r++; } } if(curr.sum >= v.back().sum) { v.push_back(curr); curr = segment(i+1, i, 0); } } cout << v.size() << '\n'; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:59:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1;j<v.size();j++)
                       ~^~~~~~~~~
segments.cpp:32:9: warning: unused variable 'answer' [-Wunused-variable]
     int answer = 0;
         ^~~~~~
#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...