結果
問題 | No.2031 Colored Brackets |
ユーザー | MtSaka |
提出日時 | 2022-08-05 21:40:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 8,689 bytes |
コンパイル時間 | 2,500 ms |
コンパイル使用メモリ | 213,716 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 17:59:12 |
合計ジャッジ時間 | 4,426 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 29 ms
5,376 KB |
testcase_05 | AC | 10 ms
5,376 KB |
testcase_06 | AC | 16 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 46 ms
5,376 KB |
testcase_09 | AC | 64 ms
5,376 KB |
testcase_10 | AC | 86 ms
5,376 KB |
testcase_11 | AC | 65 ms
5,376 KB |
testcase_12 | AC | 95 ms
5,376 KB |
testcase_13 | AC | 45 ms
5,376 KB |
testcase_14 | AC | 97 ms
5,376 KB |
testcase_15 | AC | 99 ms
5,376 KB |
testcase_16 | AC | 98 ms
5,376 KB |
testcase_17 | AC | 204 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 3 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
ソースコード
#line 2 "library/template/template.hpp" //#pragma GCC target("avx") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define overload4(a,b,c,d,e,...) e #define overload3(a,b,c,d,...) d #define rep1(a) for(ll i=0;i<(ll)(a);i++) #define rep2(i,a) for(ll i=0;i<(ll)(a);i++) #define rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep4(i,a,b,c) for(ll i=(ll)(a);i<(ll)(b);i+=(ll)(c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep1(a) for(ll i=(ll)(a)-1;i>=0;i--) #define rrep2(i,a) for(ll i=(ll)(a)-1;i>=0;i--) #define rrep3(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);i--) #define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define fore(...) for (auto&& __VA_ARGS__) #define all1(i) begin(i),end(i) #define all2(i,a) begin(i),begin(i)+a #define all3(i,a,b) begin(i)+a,begin(i)+b #define all(...) overload3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__) #define rall(n) (n).rbegin(),(n).rend() #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) #define pb push_back #define eb emplace_back #define END(...) {print(__VA_ARGS__);return;} using namespace std; using ll=long long; using ull=unsigned long long; using ld=long double; using vl=vector<ll>; using vi=vector<int>; using vs=vector<string>; using vc=vector<char>; using vvl=vector<vl>; using pi=pair<int,int>; using pl=pair<ll,ll>; using vvc=vector<vc>; using vd=vector<double>; using vp=vector<pl>; using vb=vector<bool>; constexpr int dx[8]={1,0,-1,0,1,-1,-1,1}; constexpr int dy[8]={0,1,0,-1,1,1,-1,-1}; constexpr ll MOD=1000000007; constexpr ll mod=998244353; constexpr ld EPS=1e-8; constexpr ld PI=3.1415926535897932384626; template<typename T,typename U> ostream &operator<<(ostream&os,const pair<T,U>&p){os<<p.first<<" "<<p.second;return os;} template<typename T,typename U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;} template<typename T> ostream &operator<<(ostream&os,const vector<T>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;} template<typename T> istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;} void scan(){} template<class Head,class... Tail> void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);} template<class T> void print(const T &t){cout<<t<<'\n';} template<class Head, class... Tail> void print(const Head &head, const Tail &... tail){cout<<head<<' ';print(tail...);} template<class... T> void fin(const T &... a){print(a...);exit(0);} template<typename T,typename U> inline bool chmax(T&a,U b){return a<b&&(a=b,true);} template<typename T,typename U> inline bool chmin(T&a,U b){return a>b&&(a=b,true);} template<typename T> class infinity{ public: static constexpr T MAX=numeric_limits<T>::max(); static constexpr T MIN=numeric_limits<T>::min(); static constexpr T value=numeric_limits<T>::max()/2; static constexpr T mvalue=numeric_limits<T>::min()/2; }; #if __cplusplus <= 201402L template<class T>constexpr T infinity<T>::value; template<class T>constexpr T infinity<T>::mvalue; template<class T>constexpr T infinity<T>::MAX; template<class T>constexpr T infinity<T>::MIN; #endif template<typename T>constexpr T INF=infinity<T>::value; constexpr long long inf=INF<ll>; inline int popcnt(ull x){ #if __cplusplus>=202002L return popcount(x); #endif x=(x&0x5555555555555555)+((x>>1)&0x5555555555555555);x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333);x=(x&0x0f0f0f0f0f0f0f0f)+((x>>4)&0x0f0f0f0f0f0f0f0f);x=(x&0x00ff00ff00ff00ff)+((x>>8)&0x00ff00ff00ff00ff);x=(x&0x0000ffff0000ffff)+((x>>16)&0x0000ffff0000ffff);return (x&0x00000000ffffffff)+((x>>32)&0x00000000ffffffff); } template<typename T,typename=void> struct is_specialize:false_type{}; template<typename T> struct is_specialize<T,typename conditional<false,typename T::iterator, void>::type>:true_type{}; template<typename T> struct is_specialize<T,typename conditional<false,decltype(T::first),void>::type>:true_type{}; template<typename T> struct is_specialize<T,enable_if_t<is_integral<T>::value,void>>:true_type{}; void dump(const char&t){cerr<<t;} void dump(const string&t){cerr<<t;} void dump(const bool&t){cerr<<(t?"true":"false");} template <typename T,enable_if_t<!is_specialize<T>::value,nullptr_t> =nullptr> void dump(const T&t){cerr<<t;} template<typename T> void dump(const T&t,enable_if_t<is_integral<T>::value>* =nullptr){string tmp;if(t==infinity<T>::value||t==infinity<T>::MAX)tmp="inf";if(is_signed<T>::value&&(t==infinity<T>::mvalue||t==infinity<T>::MIN))tmp="-inf";if(tmp.empty())tmp=to_string(t);cerr<<tmp;} template<typename T,typename U> void dump(const pair<T,U>&); template<typename T> void dump(const T&t,enable_if_t<!is_void<typename T::iterator>::value>* =nullptr){cerr<<"{";for(auto it=t.begin();it!=t.end();){dump(*it);cerr<<(++it==t.end()?"":",");}cerr<<"}";} template<typename T,typename U> void dump(const pair<T,U>&t){cerr<<"(";dump(t.first);cerr<<",";dump(t.second);cerr<<")";} void trace(){cerr<<endl;} template<typename Head,typename... Tail> void trace(Head&&head,Tail&&... tail){dump(head);if(sizeof...(tail))cerr<<",";trace(forward<Tail>(tail)...);} #ifdef ONLINE_JUDGE #define debug(...) (void(0)) #else #define debug(...) do{cerr<<#__VA_ARGS__<<"=";trace(__VA_ARGS__);}while(0) #endif struct IOSetup{IOSetup(){cin.tie(nullptr);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(12);cerr<<fixed<<setprecision(12);}}; template<class F>struct REC{F f;REC(F&&f_):f(std::forward<F>(f_)){}template<class...Args>auto operator()(Args&&...args)const{return f(*this, std::forward<Args>(args)...);}}; /** * @brief Template(テンプレート) */ #line 2 "library/Math/modular/modint.hpp" template<int m> struct modint{ private: unsigned int x; static constexpr unsigned int umod(){return m;} public: static modint raw(int v){ modint ret; ret.x=v; return ret; } constexpr modint():x(0){} constexpr modint(int y){ int v=y%m; if(v<0)v+=m; x=(unsigned int)v; } constexpr modint(long long y){ long long v=y%(long long)m; if(v<0)v+=m; x=(unsigned int)v; } constexpr modint(unsigned int y){ x=(unsigned int)(y%umod()); } modint& operator++(){x++;if(x==umod())x=0;return *this;} modint& operator--(){if(x==0)x=umod();x--;return *this;} modint operator++(int){ modint ret=*this; ++*this; return ret; } modint operator--(int){ modint ret=*this; --*this; return ret; } modint& operator+=(const modint&p){if((x+=p.x)>=umod())x-=umod();return *this;} modint& operator-=(const modint&p){if((x-=p.x)>=umod())x+=umod();return *this;} modint& operator*=(const modint&p){ unsigned long long y=x; y*=p.x; x=(unsigned int)(y%umod()); return *this; } modint& operator/=(const modint&p){return *this*=p.inv();} modint operator+()const{return *this;} modint operator-()const{return modint()-*this;} modint pow(long long n)const{ modint ret(1),mul=*this; while(n){ if(n&1)ret*=mul; mul*=mul; n>>=1; } return ret; } modint inv()const{ long long a=x,b=m,u=1,v=0; while(b){ long long t=a/b; swap(a-=t*b,b); swap(u-=t*v,v); } return modint(u); } friend modint operator+(const modint&l,const modint&r){return modint(l)+=r;} friend modint operator-(const modint&l,const modint&r){return modint(l)-=r;} friend modint operator*(const modint&l,const modint&r){return modint(l)*=r;} friend modint operator/(const modint&l,const modint&r){return modint(l)/=r;} friend bool operator==(const modint&l,const modint&r){return l.x==r.x;} friend bool operator!=(const modint&l,const modint&r){return l.x!=r.x;} friend ostream &operator<<(ostream &os,const modint&p) { return os<<p.val(); } friend istream &operator>>(istream &is, modint &a) { long long t; is>>t; a=modint(t); return (is); } static constexpr int get_mod(){return m;} int val()const{return (int)x;} }; /** * @brief modint */ #line 3 "code.cpp" using mint=modint<mod>; int main(){ LL(n); STR(s); vl a(n); rep(i,n){ if(i)a[i]+=a[i-1]; if(s[i]=='(')a[i]++; else a[i]--; } map<ll,mint>dp; dp[0]=1; rep(i,n){ map<ll,mint>ndp; for(auto&[j,k]:dp){ if(j+(s[i]=='('?1:-1)>=0)ndp[j+(s[i]=='('?1:-1)]+=k; if(a[i]-j>=0)ndp[j]+=k; } swap(dp,ndp); } mint ans=0; for(auto&[j,k]:dp)ans+=k; print(ans); }