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 <bits/stdc++.h>
#define int long long
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 1000000 + 3;
int n, a[N], sum, nsum;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
int mn = inf;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++)
sum += a[i];
int ind = -1, ind1 = -1;
for (int i = 0; i < n; i++){
nsum += a[i];
if (nsum * 2 == sum){
ind = i;
break;
}
if (i + 1 < n && nsum * 2 == sum - a[i + 1]){
ind1 = i;
break;
}
}
if (ind == -1 && ind1 == -1){
cout << n - 1;
return 0;
}
vector <int> v[2];
for (int i = 0; i < n; i++){
if (i <= ind || i <= ind1) v[0].push_back(a[i]);
else v[1].push_back(a[i]);
}
reverse(all(v[1]));
if (ind1 != -1) v[1].pop_back();
// for (auto u: v[0]) cout << u << " "; cout << "!\n";
// for (auto u: v[1]) cout << u << " "; cout << "!\n";
int i1 = 0, i2 = 0, ans = 0;
while (i1 < v[0].size()){
int j1 = i1 + 1;
int j2 = i2 + 1;
int sum1 = v[0][i1];
int sum2 = v[1][i2];
while (sum1 != sum2){
while (sum1 < sum2) sum1 += v[0][j1++], ans++;
while (sum2 < sum1) sum2 += v[1][j2++], ans++;
}
i1 = j1;
i2 = j2;
}
cout << ans;
}
Compilation message (stderr)
nizin.cpp: In function 'int32_t main()':
nizin.cpp:53:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i1 < v[0].size()){
~~~^~~~~~~~~~~~~
nizin.cpp:21:9: warning: unused variable 'mn' [-Wunused-variable]
int mn = inf;
^~
# | 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... |
# | 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... |