結果
問題 | No.2899 Taffy Permutation |
ユーザー |
|
提出日時 | 2024-09-28 13:55:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 774 bytes |
コンパイル時間 | 5,690 ms |
コンパイル使用メモリ | 309,464 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-28 13:55:55 |
合計ジャッジ時間 | 5,827 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>#if __has_include(<atcoder/all>)#include <atcoder/all>using namespace atcoder;#endif#define rep(i, n) for (int i = 0; i < (n); ++i)using namespace std;using mint = modint998244353;int main() {int n;string s;cin >> n >> s;vector<mint> dp(n+1);dp[0] = 1;rep(i, n) {int m = n-i;vector<mint> old(m);swap(dp, old);if (s[i] == '1') {rep(j, m) dp[j] = old[j]*(n-i-j);}else {rep(j, m) dp[j] = old[j+1]*(j+1);mint sum;rep(j, m) {sum += old[j];dp[j] += sum;}}}mint ans = dp[0];cout << ans.val() << '\n';return 0;}