#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, a[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int l = 1, r = n, cnt = 0;
for (; l < r; ) {
if (a[l] == a[r]) {
l++;
r--;
// (l + 1, r - 1)
}
else {
if (a[l] > a[r]) {
a[r - 1] += a[r];
r--;
// (l, r - 1)
}
else {
a[l + 1] += a[l];
l++;
// (l + 1, r)
}
cnt++;
}
}
cout << cnt;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2652 KB |
Output is correct |
2 |
Correct |
9 ms |
2652 KB |
Output is correct |
3 |
Correct |
5 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3072 KB |
Output is correct |
2 |
Correct |
22 ms |
3324 KB |
Output is correct |
3 |
Correct |
33 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
4296 KB |
Output is correct |
2 |
Correct |
52 ms |
4432 KB |
Output is correct |
3 |
Correct |
43 ms |
5108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
5440 KB |
Output is correct |
2 |
Correct |
46 ms |
5488 KB |
Output is correct |
3 |
Correct |
50 ms |
5444 KB |
Output is correct |