#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){
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
11024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
284 ms |
47724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
383 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
378 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |