結果
| 問題 |
No.2899 Taffy Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 13:44:27 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 844 bytes |
| コンパイル時間 | 3,818 ms |
| コンパイル使用メモリ | 184,404 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2024-08-23 14:02:07 |
| 合計ジャッジ時間 | 5,254 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
vector dp(n, vector<mint>(n));
if(s[0]=='1'){
dp[0][0]=n;
} else {
for(int j=0;j<n;++j){
dp[0][j]=1;
}
}
for(int i=1;i<n;++i){
if(s[i]=='1'){
for(int j=0;i+j<n;++j){
dp[i][j]=dp[i-1][j]*(n-i-j);
}
} else {
mint dpsum=0;
for(int j=0;j<n;++j){
dpsum+=dp[i-1][j];
dp[i][j]+=dpsum;
}
for(int j=1;j<n;++j){
dp[i][j-1]+=dp[i-1][j]*j;
}
}
}
cout << dp[n-1][0].val() << endl;
return 0;
}