update
This commit is contained in:
parent
675df5e825
commit
2ab924b825
24
src/U206625/U206625_video.cpp
Normal file
24
src/U206625/U206625_video.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using std::cin, std::cout, std::string;
|
||||
using ull = unsigned long long;
|
||||
|
||||
constexpr size_t MAX_N {(size_t)3e5+5}, MOD {998244353};
|
||||
string s;
|
||||
ull left_ok[MAX_N], stk[MAX_N], stk_size, left_index[MAX_N], ans;
|
||||
|
||||
int main(){
|
||||
cin>>s;
|
||||
|
||||
for(size_t i {1};i<=s.size();i++){
|
||||
if(s[i-1]=='('){
|
||||
stk[stk_size++] = i;
|
||||
}else if(stk_size>0){
|
||||
left_index[i] = stk[--stk_size];
|
||||
left_ok[i] = (left_ok[left_index[i]-1] + left_index[i]) % MOD;
|
||||
ans = ( ans + left_ok[i] * (s.size() - i + 1)) % MOD;
|
||||
}
|
||||
}
|
||||
cout<<ans<<'\n';
|
||||
}
|
Loading…
Reference in New Issue
Block a user