Skip to content

Instantly share code, notes, and snippets.

@axayjha
Created April 1, 2019 09:41
Show Gist options
  • Save axayjha/4e642ea46adcaefb8dcc9fa2d4ff002d to your computer and use it in GitHub Desktop.
Save axayjha/4e642ea46adcaefb8dcc9fa2d4ff002d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int count_zero_seq(vector <int> seq)
{
int n = seq.size();
int count = 0;
for (int len = 1; len <= n; len++)
{
for (int i = 0; i <= n - len; i++)
{
int summ = 0;
int j = i + len - 1;
for (int k = i; k <= j; k++)
summ += seq[k];
if (summ == 0) count ++;
}
}
return count;
}
int main()
{
int n;
vector<int> seq;
cin >> n;
for (int i = 0; i < n; i++)
{
int j;
cin >> j;
seq.push_back(j);
}
cout << count_zero_seq(seq) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment