結果
| 問題 | No.2899 Taffy Permutation | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-09-18 14:56:01 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 846 bytes | 
| コンパイル時間 | 3,135 ms | 
| コンパイル使用メモリ | 183,780 KB | 
| 実行使用メモリ | 19,200 KB | 
| 最終ジャッジ日時 | 2024-09-18 14:57:09 | 
| 合計ジャッジ時間 | 4,027 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 WA * 16 | 
ソースコード
#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=1;i+j<n;++j){
                dp[i][j-1]=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;
}
            
            
            
        