답안 #743645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743645 2023-05-17T15:11:30 Z bgnbvnbv Nizin (COCI16_nizin) C++14
100 / 100
69 ms 10180 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll a[maxN];

ll f(ll l,ll r)
{
    if(l>=r) return 0;
    ll i=l;
    ll j=r;
    ll sum1=a[i];
    ll sum2=a[j];
    while(j-i>1)
    {
        if(sum1==sum2) break;
        if(sum1<sum2) i++,sum1+=a[i];
        else j--,sum2+=a[j];
    }
    if(sum1!=sum2) return r-l;
    return (i-l)+(r-j)+f(i+1,j-1);
}
ll n;
void solve()
{
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    cout << f(1,n);
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 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 1 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 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 980 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 6 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3648 KB Output is correct
2 Correct 32 ms 4464 KB Output is correct
3 Correct 26 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 7756 KB Output is correct
2 Correct 57 ms 8140 KB Output is correct
3 Correct 56 ms 9188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 9932 KB Output is correct
2 Correct 68 ms 10180 KB Output is correct
3 Correct 69 ms 10100 KB Output is correct