結果
| 問題 | No.2899 Taffy Permutation |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-29 21:43:23 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 2,000 ms |
| コード長 | 718 bytes |
| 記録 | |
| コンパイル時間 | 1,113 ms |
| コンパイル使用メモリ | 219,956 KB |
| 実行使用メモリ | 66,304 KB |
| 最終ジャッジ日時 | 2026-07-05 20:32:06 |
| 合計ジャッジ時間 | 3,095 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int main(){
int n;
cin>>n;
string s;
cin>>s;
s=" "+s;
vector<vector<long long>> dp(n+2,vector<long long> (n+2));
vector<vector<long long>> sum(n+2,vector<long long> (n+2));
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]=(dp[i-1][j]*(n-i-j+1)+sum[i-1][j+1])%mod;
} else {
dp[i][j]=(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;
}
vjudge1