#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;
}
for(k=1;k<=n;k++)
{
if(s[k-1]=='('){
gaxs++;
shekr.push_back(0);
}
else{
if(gaxs==0)
{
shekr.clear();
continue;
}
if(k>1 && s[k-2]=='(')
{
shekr[shekr.size()-1]++;
ans+=shekr[shekr.size()-1];
}
else
{
if(shekr.size()>0) shekr.pop_back();
ans+=1;
ans+=shekr[shekr.size()-1];
shekr[shekr.size()-1]++;
continue;
}
gaxs--;
}
}
gaxs=0;
shekr.clear();
for(k=n;k>=1;k--)
{
if(s[k-1]=='('){
gaxs++;
shekr.push_back(0);
}
else{
if(gaxs==0)
{
shekr.clear();
continue;
}
if(k>1 && s[k-2]=='(')
{
shekr[shekr.size()-1]++;
ans+=shekr[shekr.size()-1];
}
else
{
if(shekr.size()>0) shekr.pop_back();
ans+=1;
ans+=shekr[shekr.size()-1];
shekr[shekr.size()-1]++;
continue;
}
gaxs--;
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
202 ms |
1868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |