#include <iostream>
int main() {
int n;
std::cin >> n;
int* uc = new int[n];
for(int i = 0; i < n; i++) {
std::cin >> uc[i];
}
int m = (n*(n+1))/2;
int* buc = new int[m];
int ibuc = 0;
for(int x = 0; x < n; x++) {
int tmp = 0;
for(int y = x; y < n; y++) {
tmp += uc[y];
buc[ibuc++] = tmp;
}
}
size_t wynik = 0;
for(int i = 1; i < m-1; i++) {
for(int x = 0; x < i; x++) {
for(int y = i + 1; y < m; y++) {
wynik += int((buc[x] + buc[i] + buc[y]) == 0);
}
}
}
std::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 | #include <iostream> int main() { int n; std::cin >> n; int* uc = new int[n]; for(int i = 0; i < n; i++) { std::cin >> uc[i]; } int m = (n*(n+1))/2; int* buc = new int[m]; int ibuc = 0; for(int x = 0; x < n; x++) { int tmp = 0; for(int y = x; y < n; y++) { tmp += uc[y]; buc[ibuc++] = tmp; } } size_t wynik = 0; for(int i = 1; i < m-1; i++) { for(int x = 0; x < i; x++) { for(int y = i + 1; y < m; y++) { wynik += int((buc[x] + buc[i] + buc[y]) == 0); } } } std::cout << wynik; return 0; } |
English