#include<bits/stdc++.h>
#define int long long
using namespace std;
int t[600];
int suma[600];
int maxx=1e7+2;
//map<int,int> mapka,mapka2;
int mapka[40000000],mapka2[40000000];
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
//n=500;
for(int i=1;i<=n;i++)
{
//t[i]=20000-i;
cin>>t[i];
}
for(int i=1;i<=n;i++)
suma[i]=suma[i-1]+t[i];
int wynik=0;
for(int x=0;x<=n;x++)
{
for(int a=0;a<=n;a++)
{
for(int b=a+1;b<=n;b++)
{
int sumaa=suma[b]-suma[a]+suma[x];
if(sumaa<0)
sumaa=-sumaa+maxx;
wynik+=mapka[sumaa];
}
}
for(int a=0;a<=n;a++)
{
for(int b=a+1;b<=n;b++)
{
int sumaa=-suma[b]+suma[a]+suma[x];
if(sumaa<0)
sumaa=-sumaa+maxx;
mapka[sumaa]++;
}
}
}
int ile=0;
for(int x=0;x<=n;x++)
for(int y=x+1;y<=n;y++)
{
int sumaa=suma[y]-suma[x];
if(sumaa==0)
wynik--;
int pomoc1=sumaa*2;
if(pomoc1<0)
pomoc1=-pomoc1+maxx;
wynik-=3*mapka2[pomoc1];
if(sumaa%2==0)
{
int pomoc2=sumaa/2;
if(pomoc2<0)
pomoc2=-pomoc2+maxx;
wynik-=3*mapka2[pomoc2];
}
int sumaa2=suma[x]-suma[y];
if(sumaa2<0)
sumaa2=-sumaa2+maxx;
mapka2[sumaa2]++;
}
wynik/=6;
cout<<wynik;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include<bits/stdc++.h> #define int long long using namespace std; int t[600]; int suma[600]; int maxx=1e7+2; //map<int,int> mapka,mapka2; int mapka[40000000],mapka2[40000000]; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; //n=500; for(int i=1;i<=n;i++) { //t[i]=20000-i; cin>>t[i]; } for(int i=1;i<=n;i++) suma[i]=suma[i-1]+t[i]; int wynik=0; for(int x=0;x<=n;x++) { for(int a=0;a<=n;a++) { for(int b=a+1;b<=n;b++) { int sumaa=suma[b]-suma[a]+suma[x]; if(sumaa<0) sumaa=-sumaa+maxx; wynik+=mapka[sumaa]; } } for(int a=0;a<=n;a++) { for(int b=a+1;b<=n;b++) { int sumaa=-suma[b]+suma[a]+suma[x]; if(sumaa<0) sumaa=-sumaa+maxx; mapka[sumaa]++; } } } int ile=0; for(int x=0;x<=n;x++) for(int y=x+1;y<=n;y++) { int sumaa=suma[y]-suma[x]; if(sumaa==0) wynik--; int pomoc1=sumaa*2; if(pomoc1<0) pomoc1=-pomoc1+maxx; wynik-=3*mapka2[pomoc1]; if(sumaa%2==0) { int pomoc2=sumaa/2; if(pomoc2<0) pomoc2=-pomoc2+maxx; wynik-=3*mapka2[pomoc2]; } int sumaa2=suma[x]-suma[y]; if(sumaa2<0) sumaa2=-sumaa2+maxx; mapka2[sumaa2]++; } wynik/=6; cout<<wynik; return 0; } |
English