結果
問題 | No.1766 Tatsujin Remix |
ユーザー | hamamu |
提出日時 | 2021-11-26 23:25:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 16,862 bytes |
コンパイル時間 | 1,896 ms |
コンパイル使用メモリ | 211,584 KB |
実行使用メモリ | 15,228 KB |
最終ジャッジ日時 | 2024-06-29 18:34:25 |
合計ジャッジ時間 | 2,950 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 14 ms
10,112 KB |
testcase_10 | AC | 13 ms
10,112 KB |
testcase_11 | AC | 13 ms
10,268 KB |
testcase_12 | AC | 14 ms
10,368 KB |
testcase_13 | AC | 16 ms
11,688 KB |
testcase_14 | AC | 22 ms
15,112 KB |
testcase_15 | AC | 21 ms
15,100 KB |
testcase_16 | AC | 20 ms
15,168 KB |
testcase_17 | AC | 22 ms
15,060 KB |
testcase_18 | AC | 20 ms
15,204 KB |
testcase_19 | AC | 20 ms
15,124 KB |
testcase_20 | AC | 22 ms
15,228 KB |
testcase_21 | AC | 21 ms
15,160 KB |
testcase_22 | AC | 21 ms
15,108 KB |
testcase_23 | AC | 21 ms
15,200 KB |
testcase_24 | AC | 19 ms
14,980 KB |
testcase_25 | AC | 21 ms
15,216 KB |
ソースコード
# include "bits/stdc++.h" #if 0 #define MODLL (1000000007LL) #else #define MODLL (998244353LL) #endif using namespace std; using ll=long long; using dd=double; using vll=vector< ll>; using vdd=vector< dd>; using vvll=vector< vll>; using vvdd=vector<vdd>; using vvvll=vector< vvll>; using vvvdd=vector<vvdd>; using vvvvll=vector<vvvll>; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using qll=tuple<ll,ll,ll,ll>; using vpll=vector< pll>; using vtll=vector< tll>; using vqll=vector< qll>; using vvpll=vector<vpll>; using vvtll=vector<vtll>; using vvqll=vector<vqll>; constexpr ll INF = 1LL << 60; struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast; #define REPS(i, S, E) for (ll i = (S); i <= (E); i++) #define REP(i, N) REPS(i, 0, (N)-1) #define DEPS(i, S, E) for (ll i = (E); i >= (S); i--) #define DEP(i, N) DEPS(i, 0, (N)-1) #define EXPAND( x ) x//VS用おまじない #define overload3(_1,_2,_3,name,...) name #define overload4(_1,_2,_3,_4,name,...) name #define overload5(_1,_2,_3,_4,_5,name,...) name #define rep3(i, S, E) for (ll i = (S); i <= (E); i++) #define rep4(i, S, E, t) for (ll i = (S); i <= (E); i+=(t)) #define rep(...) EXPAND(overload4(__VA_ARGS__,rep4,rep3,_,_)(__VA_ARGS__)) #define dep3(i, E, S) for (ll i = (E); i >= (S); i--) #define dep4(i, E, S, t) for (ll i = (E); i >= (S); i-=(t)) #define dep(...) EXPAND(overload4(__VA_ARGS__, dep4, dep3,_,_)(__VA_ARGS__)) #define each2(e,v) for (auto && e:v) #define each3(a,b,v) for (auto &&[a,b]:v) #define each4(a,b,c,v) for (auto &&[a,b,c]:v) #define each5(a,b,c,d,v) for (auto &&[a,b,c,d]:v) #define each(...) EXPAND(overload5(__VA_ARGS__,each5,each4,each3,each2,_)(__VA_ARGS__)) #define ALL1(v) (v).begin(), (v).end() #define ALL2(v,E) (v).begin(), (v).begin()+((E)+1) #define ALL3(v,S,E) (v).begin()+(S), (v).begin()+((E)+1) #define ALL(...) EXPAND(overload3(__VA_ARGS__, ALL3, ALL2, ALL1)(__VA_ARGS__)) #define all ALL #define RALL1(v) (v).rbegin(), (v).rend() #define RALL2(v,E) (v).rbegin(), (v).rbegin()+((E)+1) #define RALL3(v,S,E) (v).rbegin()+(S), (v).rbegin()+((E)+1) #define RALL(...) EXPAND(overload3(__VA_ARGS__, RALL3, RALL2, RALL1)(__VA_ARGS__)) #define rall RALL template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; } template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; } template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; } template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; } template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); } template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); } template<class T> inline auto maxe(T &&v,ll S,ll E){ return *max_element(ALL(v,S,E)); } template<class T> inline auto maxe(T &&v){ return *max_element(ALL(v)); } template<class T> inline auto mine(T &&v,ll S,ll E){ return *min_element(ALL(v,S,E)); } template<class T> inline auto mine(T &&v){ return *min_element(ALL(v)); } template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; } template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); } template<class T,class U=typename remove_reference<T>::type::value_type> inline U sum(T &&v,ll S,ll E) {return accumulate(all(v,S,E),U());} template<class T> inline auto sum(T &&v) {return sum(v,0,v.end()-v.begin()-1);} template<class T> inline ll sz(T &&v){ return (ll)v.size(); } inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } //負もOK inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } //負もOK //pair用テンプレート template<class T,class S> inline pair<T,S>& operator+=(pair<T,S> &a,const pair<T,S> &b){ a.first+=b.first; a.second+=b.second; return a; } template<class T,class S> inline pair<T,S>& operator-=(pair<T,S> &a,const pair<T,S> &b){ a.first-=b.first; a.second-=b.second; return a; } template<class T,class S> inline pair<T,S>& operator*=(pair<T,S> &a,const pair<T,S> &b){ a.first*=b.first; a.second*=b.second; return a; } template<class T,class S> inline pair<T,S>& operator/=(pair<T,S> &a,const pair<T,S> &b){ a.first/=b.first; a.second/=b.second; return a; } template<class T,class S> inline pair<T,S>& operator%=(pair<T,S> &a,const pair<T,S> &b){ a.first%=b.first; a.second%=b.second; return a; } template<class T,class S,class R> inline pair<T,S>& operator+=(pair<T,S> &a,R b){ a.first+=b; a.second+=b; return a; } template<class T,class S,class R> inline pair<T,S>& operator-=(pair<T,S> &a,R b){ a.first-=b; a.second-=b; return a; } template<class T,class S,class R> inline pair<T,S>& operator*=(pair<T,S> &a,R b){ a.first*=b; a.second*=b; return a; } template<class T,class S,class R> inline pair<T,S>& operator/=(pair<T,S> &a,R b){ a.first/=b; a.second/=b; return a; } template<class T,class S,class R> inline pair<T,S>& operator%=(pair<T,S> &a,R b){ a.first%=b; a.second%=b; return a; } template<class T,class S,class R> inline pair<T,S> operator+(const pair<T,S> &a,R b){ pair<T,S> c=a; return c+=b; } template<class T,class S,class R> inline pair<T,S> operator-(const pair<T,S> &a,R b){ pair<T,S> c=a; return c-=b; } template<class T,class S,class R> inline pair<T,S> operator*(const pair<T,S> &a,R b){ pair<T,S> c=a; return c*=b; } template<class T,class S,class R> inline pair<T,S> operator/(const pair<T,S> &a,R b){ pair<T,S> c=a; return c/=b; } template<class T,class S,class R> inline pair<T,S> operator%(const pair<T,S> &a,R b){ pair<T,S> c=a; return c%=b; } template<class T,class S,class R> inline pair<T,S> operator-(R b,const pair<T,S> &a){ pair<T,S> c=-a; return c+=b; } template<class T,class S> inline pair<T,S> operator-(const pair<T,S> &a,const pair<T,S> &b){ pair<T,S> c=a; return c-=b; } template<class T,class S> inline pair<T,S> operator-(const pair<T,S> &a){ pair<T,S> c=a; return c*=(-1); } template<class T,class S> inline ostream &operator<<(ostream &os,const pair<T,S> &a){ return os << a.first << ' ' << a.second; } //vector用テンプレート template<class T> inline vector<T>& operator+=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]+=b[i]; return a; } template<class T> inline vector<T>& operator-=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]-=b[i]; return a; } template<class T> inline vector<T>& operator*=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]*=b[i]; return a; } template<class T> inline vector<T>& operator/=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]/=b[i]; return a; } template<class T> inline vector<T>& operator%=(vector<T> &a,const vector<T> &b){ for (ll i=0; i<(ll)a.size(); i++) a[i]%=b[i]; return a; } template<class T,class S> inline vector<T>& operator+=(vector<T> &a,S b){ for (T &e: a) e+=b; return a; } template<class T,class S> inline vector<T>& operator-=(vector<T> &a,S b){ for (T &e: a) e-=b; return a; } template<class T,class S> inline vector<T>& operator*=(vector<T> &a,S b){ for (T &e: a) e*=b; return a; } template<class T,class S> inline vector<T>& operator/=(vector<T> &a,S b){ for (T &e: a) e/=b; return a; } template<class T,class S> inline vector<T>& operator%=(vector<T> &a,S b){ for (T &e: a) e%=b; return a; } template<class T,class S> inline vector<T> operator+(const vector<T> &a,S b){ vector<T> c=a; return c+=b; } template<class T,class S> inline vector<T> operator-(const vector<T> &a,S b){ vector<T> c=a; return c-=b; } template<class T,class S> inline vector<T> operator*(const vector<T> &a,S b){ vector<T> c=a; return c*=b; } template<class T,class S> inline vector<T> operator/(const vector<T> &a,S b){ vector<T> c=a; return c/=b; } template<class T,class S> inline vector<T> operator%(const vector<T> &a,S b){ vector<T> c=a; return c%=b; } template<class T,class S> inline vector<T> operator-(S b,const vector<T> &a){ vector<T> c=-a; return c+=b; } template<class T> inline vector<T> operator-(const vector<T> &a,const vector<T> &b){ vector<T> c=a; return c-=b; } template<class T> inline vector<T> operator-(const vector<T> &a){ vector<T> c=a; return c*=(-1); } template<class T> inline ostream &operator<<(ostream &os,const vector<T> &a){ for (ll i=0; i<(ll)a.size(); i++) os<<(i>0?" ":"")<<a[i]; return os; } //array用テンプレート template<class T,size_t S> inline array<T,S>& operator+=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]+=b[i]; return a; } template<class T,size_t S> inline array<T,S>& operator-=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]-=b[i]; return a; } template<class T,size_t S> inline array<T,S>& operator*=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]*=b[i]; return a; } template<class T,size_t S> inline array<T,S>& operator/=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]/=b[i]; return a; } template<class T,size_t S> inline array<T,S>& operator%=(array<T,S> &a,const array<T,S> &b){ for (ll i=0; i<(ll)S; i++) a[i]%=b[i]; return a; } template<class T,size_t S,class R> inline array<T,S>& operator+=(array<T,S> &a,R b){ for (T &e: a) e+=b; return a; } template<class T,size_t S,class R> inline array<T,S>& operator-=(array<T,S> &a,R b){ for (T &e: a) e-=b; return a; } template<class T,size_t S,class R> inline array<T,S>& operator*=(array<T,S> &a,R b){ for (T &e: a) e*=b; return a; } template<class T,size_t S,class R> inline array<T,S>& operator/=(array<T,S> &a,R b){ for (T &e: a) e/=b; return a; } template<class T,size_t S,class R> inline array<T,S>& operator%=(array<T,S> &a,R b){ for (T &e: a) e%=b; return a; } template<class T,size_t S,class R> inline array<T,S> operator+(const array<T,S> &a,R b){ array<T,S> c=a; return c+=b; } template<class T,size_t S,class R> inline array<T,S> operator-(const array<T,S> &a,R b){ array<T,S> c=a; return c-=b; } template<class T,size_t S,class R> inline array<T,S> operator*(const array<T,S> &a,R b){ array<T,S> c=a; return c*=b; } template<class T,size_t S,class R> inline array<T,S> operator/(const array<T,S> &a,R b){ array<T,S> c=a; return c/=b; } template<class T,size_t S,class R> inline array<T,S> operator%(const array<T,S> &a,R b){ array<T,S> c=a; return c%=b; } template<class T,size_t S,class R> inline array<T,S> operator-(R b,const array<T,S> &a){ array<T,S> c=-a; return c+=b; } template<class T,size_t S> inline array<T,S> operator-(const array<T,S> &a,const array<T,S> &b){ array<T,S> c=a; return c-=b; } template<class T,size_t S> inline array<T,S> operator-(const array<T,S> &a){ array<T,S> c=a; return c*=(-1); } template<class T,size_t S> inline ostream &operator<<(ostream &os,const array<T,S> &a){ for (ll i=0; i<(ll)S; i++) os<<(i>0?" ":"")<<a[i]; return os; } template<ll MOD> struct mll_{ ll val; mll_(ll v = 0): val(v % MOD){ if (val < 0) val += MOD; } mll_ operator - () const { return -val; } mll_ operator + (const mll_ &b) const { return val + b.val; } mll_ operator - (const mll_ &b) const { return val - b.val; } mll_ operator * (const mll_ &b) const { return val * b.val; } mll_ operator / (const mll_ &b) const { return mll_(*this) /= b; } mll_ operator + (ll b) const { return *this + mll_(b); } mll_ operator - (ll b) const { return *this - mll_(b); } mll_ operator * (ll b) const { return *this * mll_(b); } friend mll_ operator + (ll a,const mll_ &b) { return b + a; } friend mll_ operator - (ll a,const mll_ &b) { return -b + a; } friend mll_ operator * (ll a,const mll_ &b) { return b * a; } friend mll_ operator / (ll a,const mll_ &b) { return mll_(a)/b; } mll_ &operator += (const mll_ &b) { val=(val+b.val)%MOD; return *this; } mll_ &operator -= (const mll_ &b) { val=(val+MOD-b.val)%MOD; return *this; } mll_ &operator *= (const mll_ &b) { val=(val*b.val)%MOD; return *this; } mll_ &operator /= (const mll_ &b) { ll c=b.val,d=MOD,u=1,v=0; while (d){ ll t = c / d; c -= t * d; swap(c,d); u -= t * v; swap(u,v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } mll_ &operator += (ll b) { return *this += mll_(b); } mll_ &operator -= (ll b) { return *this -= mll_(b); } mll_ &operator *= (ll b) { return *this *= mll_(b); } mll_ &operator /= (ll b) { return *this /= mll_(b); } bool operator == (const mll_ &b) const { return val == b.val; } bool operator != (const mll_ &b) const { return val != b.val; } bool operator == (ll b) const { return *this == mll_(b); } bool operator != (ll b) const { return *this != mll_(b); } friend bool operator == (ll a,const mll_ &b) { return mll_(a) == b.val; } friend bool operator != (ll a,const mll_ &b) { return mll_(a) != b.val; } friend ostream &operator << (ostream &os,const mll_ &a) { return os << a.val; } friend istream &operator >> (istream &is,mll_ &a) { return is >> a.val; } static mll_ Combination(ll a,ll b){ chmin(b,a-b); if (b<0) return mll_(0); mll_ c = 1; rep(i,0,b-1) c *= a-i; rep(i,0,b-1) c /= i+1; return c; } enum{modll=MOD}; }; #if 1 using mll = mll_<MODLL>; using vmll = std::vector<mll>; using vvmll = std::vector<vmll>; using vvvmll = std::vector<vvmll>; using vvvvmll = std::vector<vvvmll>; #endif ////////////////////////////////////////// #if defined(_DEBUG) ll dumpW = 5; template<class T> void dump(vector<T> &v){ rep(i,0,sz(v)-1) { cerr << ((i==0)?"[":" ") << setw(dumpW) << v[i]; } cerr << "]"; } void dump(vll &v){ rep(i,0,sz(v)-1) { cerr << ((i==0)?"[":" ") << setw(dumpW); if (v[i] == INF) cerr << "INF"; else if (v[i] == -INF) cerr << "-INF"; else cerr << v[i]; } cerr << "]"; } template<class T> void dump(vector<vector<T>> &v){ ll N=(ll)v.size(); string d[2][2]={{" ", "["}, {"\n", "]\n"}}; rep(i,0,N-1) { cerr << d[0][i==0]; dump(v[i]); cerr << d[1][i==N-1]; } } template<class T> void dump(vector<vector<vector<T>>> &v){ ll N=(ll)v.size(); string d[2]={" <", "[ <"}; rep(i,0,N-1) { cerr << d[i==0] << i << ">\n"; dump(v[i]); } cerr << "]\n"; } template<class T> void dump(vector<vector<vector<vector<T>>>> &v){ ll N=(ll)v.size(); string d[2]={" ---<", "[ ---<"}; rep(i,0,N-1) { cerr << d[i==0] << i << ">---\n"; dump(v[i]); } cerr << "]\n"; } template<class T> void dump(vector<vector<vector<vector<vector<T>>>>> &v){ ll N=(ll)v.size(); string d[2]={" ======<", "[ ======<"}; rep(i,0,N-1) { cerr << d[i==0] << i << ">======\n"; dump(v[i]); } cerr << "]\n"; } template<class T,class S> void dump(map<T,S> &m){ for (auto e: m) cout << e.first << " : " << e.second << '\n'; } #else template<class T> void dump(T &v){} #endif auto solve( ll n_,string &t ){ ll n=sz(t),m=3; vvmll dp_(n,vmll(m)); auto dp = [&](ll i,ll s)->mll&{ static mll dmy=0; return dp_[i][s]; }; rep(i,-1,n-2){ rep(ss,0,m-1){ ll c=t[i+1]; ll tt = (c=='.') ? 0 : (c=='d') ? 1 : 2; if (tt!=0 and ss!=tt)continue; if (i!=n-2){ ll cc=t[i+2]; ll ttt = (cc=='.') ? 0 : (cc=='d') ? 1 : 2; if (tt==0 and ss!=0 and ss==ttt)continue; } if (i==-1){ dp(0,ss)=1; continue; } rep(s,0,m-1){ if (i%2==0){ if (s==0 and ss!=0)continue; } else{ if (s!=0 and ss==0)continue; } dp(i+1,ss)+=dp(i,s); } } } mll ans=dp(n-1,0)+dp(n-1,1)+dp(n-1,2); //dump(dp_); return ans; } void solvecomp( ll n,string &s ){ auto coutans=[](auto ans){ /* 出力を書く */ cout << ans << '\n'; }; auto ans=solve( n,s ); coutans(ans); #if 0 cout << "- - - - -\n"; auto an2=solv2( n,s ); coutans(an2); cout << "================\n"; if (ans!=an2){ cout << "============ input =============\n"; /* inputファイルの形式で吐き出す */ cout << "============ input end =========\n\n================\n"; getchar(); rep(i,0,10000000000) i++;//getchar()の代わり } #endif } void cin2solve(){ /* cinからの入力を書く */ ll n; cin >> n; vector<string> ss; rep(i,0,n-1){ string ss__; cin>>ss__; ss.push_back(ss__); } string s; for (auto&& e: ss){ s+=e; } solvecomp( n,s ); } ////////////////////////////////////////// int main(){ using namespace chrono; auto st=system_clock::now(); #if 1 cin2solve(); //generand(); #else ll t; cin >> t; rep(i,0,t-1){ cin2solve(); //generand(); } #endif ll ms=duration_cast<microseconds>(system_clock::now()-st).count()/1000; cerr << ms <<"ms"<< '\n'; return 0; }