#include<bits/stdc++.h>
using namespace std;
long long n,l1,l2,k,ans,gaxs;
vector<long long> shekr;
string s;
int main()
{
cin>>n;
cin>>s;
for(k=1;k<=n-1;k++)
{
cin>>l1>>l2;
}
shekr.push_back(0);
for(k=1;k<=n;k++)
{
if(s[k-1]=='('){
gaxs++;
shekr.push_back(0);
}
else{
if(gaxs==0)
{
shekr.clear();
shekr.push_back(0);
continue;
}
else
{
if(shekr.size()>0) shekr.pop_back();
ans+=1;
ans+=shekr[shekr.size()-1];
shekr[shekr.size()-1]++;
}
gaxs--;
}
}
gaxs=0;
shekr.clear();
shekr.push_back(0);
for(k=n;k>=1;k--)
{
if(s[k-1]=='('){
gaxs++;
shekr.push_back(0);
}
else{
if(gaxs==0)
{
shekr.clear();
shekr.push_back(0);
continue;
}
else
{
if(shekr.size()>0) shekr.pop_back();
ans+=1;
ans+=shekr[shekr.size()-1];
shekr[shekr.size()-1]++;
}
gaxs--;
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
1104 KB |
Output is correct |
2 |
Correct |
238 ms |
860 KB |
Output is correct |
3 |
Correct |
211 ms |
860 KB |
Output is correct |
4 |
Correct |
220 ms |
860 KB |
Output is correct |
5 |
Correct |
214 ms |
860 KB |
Output is correct |
6 |
Correct |
211 ms |
1344 KB |
Output is correct |
7 |
Correct |
210 ms |
860 KB |
Output is correct |
8 |
Correct |
230 ms |
1344 KB |
Output is correct |
9 |
Correct |
260 ms |
860 KB |
Output is correct |
10 |
Correct |
211 ms |
2872 KB |
Output is correct |
11 |
Correct |
208 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |