#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 503;
const int OFS = 1e7;
const int W = 2e7+3;
int arr[N];
vector<int> tab;
int cnt[W];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i=0; i<n; i++) cin >> arr[i];
for(int i=0; i<n; i++){
int sm=0;
for(int j=i; j<n; j++){
sm+=arr[j];
tab.pb(sm);
}
}
n=tab.size();
int out=0;
for(int i=1; i<n; i++){
cnt[tab[i-1]+OFS]++;
for(int j=i+1; j<n; j++){
out+=cnt[OFS-tab[i]-tab[j]];
}
}
cout << out << '\n';
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 | #include <bits/stdc++.h> using namespace std; #define pb push_back const int N = 503; const int OFS = 1e7; const int W = 2e7+3; int arr[N]; vector<int> tab; int cnt[W]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i=0; i<n; i++) cin >> arr[i]; for(int i=0; i<n; i++){ int sm=0; for(int j=i; j<n; j++){ sm+=arr[j]; tab.pb(sm); } } n=tab.size(); int out=0; for(int i=1; i<n; i++){ cnt[tab[i-1]+OFS]++; for(int j=i+1; j<n; j++){ out+=cnt[OFS-tab[i]-tab[j]]; } } cout << out << '\n'; return 0; } |
English