update
This commit is contained in:
parent
100e97ef6e
commit
560b5bd6aa
@ -1,51 +1,25 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stack>
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
#include <ranges>
|
||||
|
||||
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;
|
||||
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;
|
||||
// ret[40]=1,ret[41]=-1;
|
||||
return ret;
|
||||
}
|
||||
constexpr array<int,char_size> map = install_array();
|
||||
ull stk[MAX_N], pre[MAX_N], g[MAX_N], ans;
|
||||
size_t tot;
|
||||
|
||||
int main(){
|
||||
// cout<<(int)'('<<' '<<(int)')'<<'\n'<<map[40]<<'\n';
|
||||
cin>>s;
|
||||
for(size_t i {0};i<s.size();i++){
|
||||
for(size_t j {i+1};j<=s.size();j++){
|
||||
// sum=0;
|
||||
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(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:;
|
||||
}
|
||||
}
|
||||
for(const size_t i:range((size_t)0,s.size())){
|
||||
if(s[i]=='('){
|
||||
stk[tot++] = i;
|
||||
}else{
|
||||
pre[i] = stk[tot--];
|
||||
g[i] = ( g[pre[i]-1] + pre[i] ) % MOD;
|
||||
ans = ( ans + g[i] * s.size()-i) % MOD;
|
||||
}
|
||||
}
|
||||
cout<<ans<<'\n';
|
||||
|
46
src/U206625/U206625_failed.cpp
Normal file
46
src/U206625/U206625_failed.cpp
Normal 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';
|
||||
}
|
Loading…
Reference in New Issue
Block a user