結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<bool>> tb(26, vector<bool>(m));
    for(int i = 0; i < t.size(); i++){
        tb[t[i] - 'a'][i] = true;
    }
    vector<mint> dp(t.size()), pow2(n);
    pow2[0] = 1;
    for(int i = 0; i + 1 < n; i++) pow2[i + 1] = pow2[i] + pow2[i];
    dp[0] = 1;
    mint ans;
    for(int i = 0; i < s.size(); i++){
        int p = s[i] - 'a';
        mint add;
        for(int j = m - 1; j >= 0; j--){
            if(tb[p][j]){
                if(j == m - 1) add = dp[j];
                else dp[j + 1] += dp[j];
            }
            dp[j] += dp[j];
        }
        dp[0] += add;
        ans += add * pow2[n - 1 - i];
    }
    cout << ans.val() << '\n';
}
0