This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)>>1)
#define N 1000005
using namespace std;
int n, ans, a[N], pre[N];
char s[N];
map < int , int > h;
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %s",&n, s + 1);
for(int i = 1; i <= n; i++){
a[i] = (s[i] == '(') ? 1 : -1;
pre[i] = pre[i - 1] + a[i];
// cout << pre[i] << " ";
}
// up(1, -n, n, 0);
h[0]++;
h[pre[1]]++;
// up(1, -n, n, pre[1]);
for(int i = 2; i <= n; i++){
ans += h[pre[i]];
h[pre[i]]++;
}
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
zagrade.cpp: In function 'int main()':
zagrade.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %s",&n, s + 1);
~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |