이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long n,l1,l2,k,ans,gaxs,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++;
}
else{
if(gaxs==0)
{
shekr=0;
continue;
}
if(gaxs>1)
{
ans+=1;
}
if(gaxs==1)
{
ans+=1;
ans+=shekr;
shekr++;
}
gaxs--;
}
}
gaxs=0;
shekr=0;
for(k=n;k>=1;k--)
{
if(s[k-1]=='('){
gaxs++;
}
else{
if(gaxs==0)
{
shekr=0;
continue;
}
if(gaxs>1)
{
ans+=1;
}
if(gaxs==1)
{
ans+=1;
ans+=shekr;
shekr++;
}
gaxs--;
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |