結果

問題 No.1740 Alone 'a'
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-10 00:43:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 204,660 KB
実行使用メモリ 33,196 KB
最終ジャッジ日時 2024-04-10 00:43:07
合計ジャッジ時間 5,780 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 126 ms
33,196 KB
testcase_04 AC 122 ms
33,116 KB
testcase_05 AC 5 ms
6,948 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 22 ms
8,704 KB
testcase_12 AC 86 ms
27,068 KB
testcase_13 AC 82 ms
25,752 KB
testcase_14 AC 121 ms
31,652 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 104 ms
24,912 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 15 ms
6,944 KB
testcase_19 AC 109 ms
27,312 KB
testcase_20 AC 51 ms
15,616 KB
testcase_21 AC 68 ms
20,352 KB
testcase_22 AC 75 ms
23,808 KB
testcase_23 AC 78 ms
23,680 KB
testcase_24 AC 52 ms
15,744 KB
testcase_25 AC 51 ms
16,000 KB
testcase_26 AC 67 ms
19,828 KB
testcase_27 AC 71 ms
21,248 KB
testcase_28 AC 59 ms
18,048 KB
testcase_29 AC 103 ms
31,452 KB
testcase_30 AC 66 ms
20,776 KB
testcase_31 AC 74 ms
24,468 KB
testcase_32 AC 58 ms
18,408 KB
testcase_33 AC 75 ms
24,192 KB
testcase_34 AC 16 ms
7,552 KB
testcase_35 AC 54 ms
17,792 KB
testcase_36 AC 47 ms
15,232 KB
testcase_37 AC 18 ms
7,680 KB
testcase_38 AC 42 ms
13,184 KB
testcase_39 AC 7 ms
6,940 KB
testcase_40 AC 26 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

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