結果
問題 | No.2899 Taffy Permutation |
ユーザー |
![]() |
提出日時 | 2024-09-25 21:13:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 833 bytes |
コンパイル時間 | 2,792 ms |
コンパイル使用メモリ | 246,568 KB |
実行使用メモリ | 34,920 KB |
最終ジャッジ日時 | 2024-09-25 21:13:54 |
合計ジャッジ時間 | 3,965 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> #define _1 (__int128)1 using namespace std; using ll = long long; void FileIO (const string s) { freopen(string(s + ".in").c_str(), "r", stdin); freopen(string(s + ".out").c_str(), "w", stdout); } const int N = 2010, mod = 998244353; int n, dp[N][N], sum[N][N]; string s; signed main () { ios::sync_with_stdio(0), cin.tie(0); // FileIO(""); cin >> n >> s, s = " " + s, 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] = (1ll * dp[i - 1][j] * (n - i - j + 1) + sum[i - 1][j + 1]) % mod; else dp[i][j] = 1ll * (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; }