結果
問題 |
No.2899 Taffy Permutation
|
ユーザー |
![]() |
提出日時 | 2024-09-29 21:43:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 718 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 200,052 KB |
最終ジャッジ日時 | 2025-02-24 14:11:12 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; const int mod=998244353; int main(){ int n; cin>>n; string s; cin>>s; s=" "+s; vector<vector<long long>> dp(n+2,vector<long long> (n+2)); vector<vector<long long>> sum(n+2,vector<long long> (n+2)); dp[0][n]=1; for (int i=1; i<=n; i++) { sum[0][i]=1; } for (int i=1; i<=n; i++) { for (int j=0; j<=n; j++) { if (s[i]=='0') { dp[i][j]=(dp[i-1][j]*(n-i-j+1)+sum[i-1][j+1])%mod; } else { dp[i][j]=(j+1)*dp[i-1][j+1]%mod; } } for (int j=n; j; j--) { sum[i][j]=(sum[i][j+1]+dp[i][j])%mod; } } cout << dp[n][0]; return 0; }