結果
問題 | No.2899 Taffy Permutation |
ユーザー |
![]() |
提出日時 | 2024-09-20 22:06:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,079 bytes |
コンパイル時間 | 4,318 ms |
コンパイル使用メモリ | 256,708 KB |
最終ジャッジ日時 | 2025-02-24 10:12:08 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001LL int main(){ int n; cin>>n; string s; cin>>s; vector<mint> dp; int pos = -1; rep(i,n){ if(s[i]=='0'){ pos = i;break; } } if(pos==-1){ mint ans = 1; rep(i,n)ans *= i+1; cout<<ans.val()<<endl; return 0; } { mint t = 1; rep(i,pos)t *= i+1; dp.resize(pos+1,t); } for(int i = pos+1;i<n;i++){ rep(j,dp.size()){ // cout<<dp[j].val()<<' '; } //cout<<endl; if(s[i]=='1'){ vector<mint> ndp(dp.size()); rep(j,dp.size()){ ndp[j] = dp[j] * (i-j); } dp = ndp; continue; } vector<mint> ndp(i+1); while(dp.size()!=ndp.size())dp.push_back(0); rep(j,dp.size()-1)ndp[j+1] += dp[j] * (j+1); rep(j,dp.size()-1){ dp[j+1] += dp[j]; } rep(j,dp.size()-1)ndp[j+1] += dp[j]; dp = ndp; } mint ans = 0; rep(i,dp.size())ans += dp[i]; cout<<ans.val()<<endl; return 0; }