This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <unistd.h>
#include <set>
#define dbg(x) cout<<#x<<" has a value of: "<<x<<"\n";
typedef long long int lli;
using namespace std;
typedef pair<lli,lli> pii;
int main(){
int n;
cin>>n;
vector<lli> dizi(n);
for (int i = 0; i < n; i++)
{
cin>>dizi[i];
}
vector<lli> fromleft(n),fromright(n);
int h=0;
int hk=0;
map<lli,pii> matches;
for (int i = 0; i < n; i++)
{
h+=dizi[i];
fromleft[i]=h;
hk+=dizi[n-i-1];
fromright[i]=hk;
}
for (int i = 0; i < n; i++)
{
if(matches.find(fromleft[i])==matches.end())matches[fromleft[i]]=pii(-1,-1);
if(matches.find(fromright[i])==matches.end())matches[fromright[i]]=pii(-1,-1);
matches[fromleft[i]].first=i;
matches[fromright[i]].second=n-i-1;
}
lli cvb=0;
int lv=-1,rv=n;
for(auto x:matches){
//dbg(x.first);
//cout<<x.second.first<<"-"<<x.second.second<<"\n";
if(x.second.first!=-1 && x.second.second!=-1){
if(x.second.first==rv-1&& x.second.second==lv+1){
cvb+=rv-2-lv;
break;
}
cvb+=max(x.second.first-lv-1,0ll)+max(rv-x.second.second-1,0ll);
lv=x.second.first;
rv=x.second.second;
if(lv==rv-1)break;
}
}
cout<<cvb<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |