結果
| 問題 |
No.2899 Taffy Permutation
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-25 19:34:44 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 845 bytes |
| コンパイル時間 | 2,364 ms |
| コンパイル使用メモリ | 162,536 KB |
| 実行使用メモリ | 30,976 KB |
| 最終ジャッジ日時 | 2024-09-25 19:34:51 |
| 合計ジャッジ時間 | 3,172 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2001, MOD = 998244353;
int n, dp[MAXN][MAXN], sum[MAXN][MAXN];
string s;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> s;
s = ' ' + s;
dp[0][n] = 1;
for(int i = 0; i <= n; ++i) {
for(int j = n - i; j >= 0; --j) {
sum[i][j] = (sum[i][j] + sum[i][j + 1]) % MOD;
dp[i][j] = (dp[i][j] + sum[i][j]) % MOD;
if(i == n) {
continue;
}
if(s[i + 1] == '1' && j) {
dp[i + 1][j - 1] = (dp[i + 1][j - 1] + 1ll * j * dp[i][j] % MOD) % MOD;
}else if(s[i + 1] == '0') {
dp[i + 1][j] = (dp[i + 1][j] + 1ll * dp[i][j] * (n - i - j) % MOD) % MOD;
if(j) {
sum[i + 1][j - 1] = (sum[i + 1][j - 1] + dp[i][j]) % MOD;
}
}
}
}
cout << dp[n][0];
return 0;
}
vjudge1