結果

問題 No.2943 Sigma String of String Score Problem
ユーザー srjywrdnprkt
提出日時 2024-10-19 21:21:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 239 ms / 3,000 ms
コード長 866 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 197,276 KB
最終ジャッジ日時 2025-02-24 21:44:17
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using ll = long long;
using namespace atcoder;
using mint=modint998244353;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    /*
       dp(i, j) = Sのi文字目まででTのj文字目までが完成するパターン数
    */

    string S, T;
    int N, M;
    cin >> S >> T;
    N = S.size(); M = T.size();
    vector<mint> dp(M+1);
    dp[0] = 1;
    
    for (int i=1; i<=N; i++){
        vector<mint> pd(M+1);
        for (int j=0; j<=M; j++){
            if (j>i) break;
            //Sがi文字目を含む
            if (j>=1 && S[i-1] == T[j-1]) pd[j] += dp[j-1];
            pd[j] += dp[j];
            //Sがi文字目を含まない
            pd[j] += dp[j];
        }
        swap(dp, pd);
    }

    cout << dp[M].val() << endl;

    return 0;
}
0