This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <map>
#include <unordered_set>
#include <tuple>
#include <queue>
#include <set>
#include <cstring>
#include <functional>
#include <random>
#include <chrono>
#include <cassert>
#include <iomanip>
// #include <ext/pb_ds/assoc_container.hpp>
#define ar array
#define all(arr) (arr).begin(), (arr).end()
#define range(i, n) for (int i=0; i < (n); ++i)
#define rall(arr) (arr).rbegin(), (arr).rend()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
// using namespace __gnu_pbds;
/*
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
const ll INF = 1e18;
const int INFi = 2e9;
const int maxN = 5e5 + 5;
const int md2 = 998244353;
const int md3 = 1e9 + 7;
double getTime() { return clock() / (double) CLOCKS_PER_SEC; }
void solve() {
int n;
cin >> n;
vector<int> a(n);
int ans = 0;
range(i, n) cin >> a[i];
vector<pair<int, ll>> segs;
segs.emplace_back(1, a[0]);
while(segs.back().first != n) {
ll cur = 0;
for(int j = segs.back().first; j < n; ++j) {
cur += a[j];
if (cur >= segs.back().second) {
segs.emplace_back(j + 1, cur);
cur = -1;
break;
}
}
if (cur != -1) break;
if (segs.back().first == n) break;
int sz = segs.size();
while(segs[sz-2].second + a[segs[sz-2].first] * 2 <= segs[sz-1].second) {
segs[sz-2].second += a[segs[sz-2].first];
segs[sz-1].second -= a[segs[sz-2].first];
segs[sz-2].first++;
}
}
cout << segs.size() << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// cout << setprecision(15) << fixed;
int tests = 1;
// cin >> tests;
range(_, tests) {
solve();
}
return 0;
}
Compilation message (stderr)
segments.cpp: In function 'void solve()':
segments.cpp:53:9: warning: unused variable 'ans' [-Wunused-variable]
53 | int ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |