#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=3e5+5;
const ll inf=2e18;
int n;
ll dp[maxN+1];
string s;
vector<int> adj[maxN+1];
stack<int> st;
void clr()
{
while(!st.empty())
{
st.pop();
}
}
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>s;
s=" "+s;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
}
for(int i=1;i<=n;i++)
{
if(s[i]=='(')
{
st.push(i);
}
else
{
if(!st.empty()&&s[st.top()]=='(')
{
dp[i]=dp[i]+dp[st.top()-1]+1;
}
else clr();
}
}
ll res=0;
for(int i=1;i<=n;i++)
{
res+=dp[i];
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
14764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |