#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sp " "
#define endl "\n"
#define N 1000005
#define modulo 1000000007
#define int long long
int arr[N];
int32_t main()
{
fastio();
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>arr[i];
int l = 0, r = n + 1, sl = 0, sr = 0, ans = 0;
int steps = 0;
while(l < r)
{
//cout<<l<<sp<<r<<endl;
while(sl != sr && l < r)
{
while(sl < sr && l < r)
{
//cout<<l<<sp<<r<<sp<<sl<<sp<<sr<<endl;
l++;
sl += arr[l];
ans++;
}
while(sr < sl && l < r)
{
//cout<<l<<sp<<r<<sp<<sl<<sp<<sr<<endl;
r--;
sr += arr[r];
ans++;
}
}
l++, r--;
sl = arr[l], sr = arr[r];
}
cout<<ans<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
Compilation message
nizin.cpp: In function 'int32_t main()':
nizin.cpp:27:6: warning: unused variable 'steps' [-Wunused-variable]
27 | int steps = 0;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
852 KB |
Output is correct |
2 |
Correct |
10 ms |
980 KB |
Output is correct |
3 |
Correct |
6 ms |
1036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2992 KB |
Output is correct |
2 |
Correct |
22 ms |
3572 KB |
Output is correct |
3 |
Correct |
28 ms |
4152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
6144 KB |
Output is correct |
2 |
Correct |
42 ms |
6476 KB |
Output is correct |
3 |
Correct |
46 ms |
7268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
7872 KB |
Output is correct |
2 |
Correct |
76 ms |
8028 KB |
Output is correct |
3 |
Correct |
58 ms |
8092 KB |
Output is correct |