結果
| 問題 |
No.2899 Taffy Permutation
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-25 12:39:25 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 2,000 ms |
| コード長 | 658 bytes |
| コンパイル時間 | 6,204 ms |
| コンパイル使用メモリ | 272,336 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 12:39:33 |
| 合計ジャッジ時間 | 4,502 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 2e3 + 10, P = 998244353;
int n, dp[N], tmp[N];
string s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> s;
dp[n] = 1;
for(int i = 0; i < n; i ++) {
if(s[i] == '0') {
for(int j = n, p = 0; j >= 0; j --) {
p += dp[j];
dp[j] = ((i64)dp[j] * (n - i - j) + p - dp[j]) % P;
p %= P;
}
}else{
for(int j = 0; j <= n; j ++)
dp[j] = dp[j + 1] * (j + 1ll) % P;
}
}
cout << accumulate(dp, dp + n + 1, 0ll) % P;
}
vjudge1