// Author: Bartek Knapik #include <cstdio> using namespace std; const int MAX_N = 125250 + 9; int n, ans, n_sum; int a[MAX_N], sums[MAX_N]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); n_sum = 0; int cur_sum; for (int i = 0; i < n; ++i) { cur_sum = a[i]; sums[n_sum++] = cur_sum; for (int j = i + 1; j < n; ++j) { cur_sum += a[j]; sums[n_sum++] = cur_sum; } } for (int i = 0; i < n_sum; ++i) for (int j = i + 1; j < n_sum; ++j) for (int k = j + 1; k < n_sum; ++k) if (sums[i] + sums[j] + sums[k] == 0) ans++; printf("%d\n", ans); 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 | // Author: Bartek Knapik #include <cstdio> using namespace std; const int MAX_N = 125250 + 9; int n, ans, n_sum; int a[MAX_N], sums[MAX_N]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); n_sum = 0; int cur_sum; for (int i = 0; i < n; ++i) { cur_sum = a[i]; sums[n_sum++] = cur_sum; for (int j = i + 1; j < n; ++j) { cur_sum += a[j]; sums[n_sum++] = cur_sum; } } for (int i = 0; i < n_sum; ++i) for (int j = i + 1; j < n_sum; ++j) for (int k = j + 1; k < n_sum; ++k) if (sums[i] + sums[j] + sums[k] == 0) ans++; printf("%d\n", ans); return 0; } |