This commit is contained in:
Zengtudor 2024-10-05 18:37:04 +08:00
parent 100e97ef6e
commit 560b5bd6aa
2 changed files with 60 additions and 40 deletions

View File

@ -1,51 +1,25 @@
#include <iostream> #include <iostream>
#include <string>
#include <stack> #include <stack>
#include <cmath> #include <ranges>
#include <array>
using std::cin, std::cout, std::string, std::stack, std::array; using std::cin, std::cout, std::string, std::stack;
using ull = unsigned long long;
constexpr auto range = std::ranges::views::iota;
constexpr size_t MOD {998244353}, MAX_N {(size_t)3e5+5}; constexpr size_t MAX_N {(size_t)3e5+5}, MOD {998244353};
string s; string s;
stack<size_t> st; ull stk[MAX_N], pre[MAX_N], g[MAX_N], ans;
unsigned int prefix[MAX_N], ans, sum, left_num; size_t tot;
constexpr size_t char_size {1<<(sizeof(char)*8)};
constexpr array<int,char_size> install_array(){
array<int,char_size> ret{};
ret[40]=1;
// ret[40]=1,ret[41]=-1;
return ret;
}
constexpr array<int,char_size> map = install_array();
int main(){ int main(){
// cout<<(int)'('<<' '<<(int)')'<<'\n'<<map[40]<<'\n';
cin>>s; cin>>s;
for(size_t i {0};i<s.size();i++){ for(const size_t i:range((size_t)0,s.size())){
for(size_t j {i+1};j<=s.size();j++){ if(s[i]=='('){
// sum=0; stk[tot++] = i;
for(size_t k{i};k<j;k++){ }else{
for(size_t l{k+1};l<=j;l++){ pre[i] = stk[tot--];
left_num = 0; g[i] = ( g[pre[i]-1] + pre[i] ) % MOD;
for(size_t m{k};m<l;m++){ ans = ( ans + g[i] * s.size()-i) % MOD;
left_num+=map[s[m]];
if(left_num<0){
goto failed;
}
if(s[m]==')'){
if(left_num<=0){
goto failed;
}
left_num--;
}
}
if(left_num==0){
ans=(ans+1)%MOD;
}
failed:;
}
}
} }
} }
cout<<ans<<'\n'; cout<<ans<<'\n';

View File

@ -0,0 +1,46 @@
#include <iostream>
#include <string>
#include <stack>
#include <cmath>
#include <array>
using std::cin, std::cout, std::string, std::stack, std::array;
constexpr size_t MOD {998244353}, MAX_N {(size_t)3e5+5};
string s;
stack<size_t> st;
unsigned int prefix[MAX_N], ans, sum, left_num;
constexpr size_t char_size {1<<(sizeof(char)*8)};
constexpr array<int,char_size> install_array(){
array<int,char_size> ret{};
ret[40]=1;
return ret;
}
constexpr array<int,char_size> map = install_array();
int main(){
cin>>s;
for(size_t i {0};i<s.size();i++){
for(size_t j {i+1};j<=s.size();j++){
for(size_t k{i};k<j;k++){
for(size_t l{k+1};l<=j;l++){
left_num = 0;
for(size_t m{k};m<l;m++){
left_num+=map[s[m]];
if(s[m]==')'){
if(left_num<=0){
goto failed;
}
left_num--;
}
}
if(left_num==0){
ans=(ans+1)%MOD;
}
failed:;
}
}
}
}
cout<<ans<<'\n';
}