#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];
}
int i1 = 0, i2 = n - 1;
int ans = 0;
while (i1 < i2){
int j1 = i1, j2 = i2, sum1 = a[i1], sum2 = a[i2];
while (j1 < j2 && sum1 != sum2){
while (sum1 < sum2 && j1 < j2) sum1 += a[++j1], ans++;
while (sum2 < sum1 && j1 < j2) sum2 += a[--j2], ans++;
}
i1 = j1 + 1;
i2 = j2 - 1;
}
cout << ans;
}
Compilation message
nizin.cpp: In function 'int32_t main()':
nizin.cpp:21:9: warning: unused variable 'mn' [-Wunused-variable]
int mn = inf;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 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 |
5 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 |
Correct |
4 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 |
6 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 |
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 |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1152 KB |
Output is correct |
2 |
Correct |
11 ms |
1280 KB |
Output is correct |
3 |
Correct |
11 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3832 KB |
Output is correct |
2 |
Correct |
32 ms |
4472 KB |
Output is correct |
3 |
Correct |
40 ms |
5240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
7804 KB |
Output is correct |
2 |
Correct |
60 ms |
8312 KB |
Output is correct |
3 |
Correct |
66 ms |
9208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
10208 KB |
Output is correct |
2 |
Correct |
73 ms |
10232 KB |
Output is correct |
3 |
Correct |
77 ms |
10232 KB |
Output is correct |