Submission #43363

# Submission time Handle Problem Language Result Execution time Memory
43363 2018-03-14T18:03:15 Z Hassoony Nizin (COCI16_nizin) C++14
100 / 100
131 ms 14692 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MX=1e6+9;
int n,a[MX];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    int p1=0,p2=n-1,ans=0;
    ll sum1=0,sum2=0;
    while(p1<p2){
        if(sum1+a[p1]-sum2-a[p2]==0){
            ++p1;
            --p2;
            sum1=sum2=0;
            continue;
        }
        if(sum1+a[p1]<sum2+a[p2]){
            sum1+=a[p1++];
            ans++;
        }
        else{
            sum2+=a[p2--];
            ans++;
        }
    }
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    cout<<ans<<endl;
}

Compilation message

nizin.cpp: In function 'int main()':
nizin.cpp:8:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
nizin.cpp:9:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++)scanf("%d",&a[i]);
                                          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 404 KB Output is correct
2 Correct 2 ms 584 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 652 KB Output is correct
3 Correct 2 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 708 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 732 KB Output is correct
3 Correct 2 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1012 KB Output is correct
2 Correct 11 ms 1268 KB Output is correct
3 Correct 12 ms 1472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2516 KB Output is correct
2 Correct 74 ms 3772 KB Output is correct
3 Correct 55 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 6064 KB Output is correct
2 Correct 131 ms 7840 KB Output is correct
3 Correct 118 ms 10052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 10460 KB Output is correct
2 Correct 115 ms 12516 KB Output is correct
3 Correct 131 ms 14692 KB Output is correct