#include <bits/stdc++.h>
#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;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int ind = -1;
for (int i = 0; i < n; i++){
nsum += a[i];
if (nsum * 2 == sum){
ind = i;
break;
}
}
if (ind == -1){
cout << n - 1;
return 0;
}
vector <int> v[2];
for (int i = 0; i < n; i++){
if (i <= ind) v[0].push_back(a[i]);
else v[1].push_back(a[i]);
}
reverse(all(v[1]));
int i1 = 0, i2 = 0, ans = 0;
while (i1 < v[0].size()){
int j1 = i1 + 1;
int j2 = i1 + 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
nizin.cpp: In function 'int main()':
nizin.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (i1 < v[0].size()){
~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
2424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
4856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
6264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |