結果

問題 No.1740 Alone 'a'
ユーザー eve__fuyuki
提出日時 2024-04-10 00:43:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 202,028 KB
最終ジャッジ日時 2025-02-20 23:36:29
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    string s;
    cin >> n >> s;
    vector dp(n + 1, vector(2, vector<mint>(2)));
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int smaller = 0; smaller < 2; smaller++) {
            for (int j = 0; j < 2; j++) {
                for (char c = 'a'; c <= (smaller ? 'z' : s[i]); c++) {
                    if (j == 1 && c == 'a') {
                        continue;
                    }
                    int smaller_next = smaller || c < s[i];
                    int j_next = j || c == 'a';
                    dp[i + 1][smaller_next][j_next] += dp[i][smaller][j];
                }
            }
        }
    }
    cout << dp[n][1][1].val() << endl;
}
0