結果

問題 No.1740 Alone 'a'
ユーザー hir355hir355
提出日時 2021-11-12 22:13:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 3,013 bytes
コンパイル時間 2,275 ms
コンパイル使用メモリ 200,984 KB
実行使用メモリ 6,772 KB
最終ジャッジ日時 2023-08-17 01:54:01
合計ジャッジ時間 4,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,500 KB
testcase_01 AC 4 ms
6,588 KB
testcase_02 AC 4 ms
6,572 KB
testcase_03 AC 40 ms
6,596 KB
testcase_04 AC 40 ms
6,624 KB
testcase_05 AC 6 ms
6,516 KB
testcase_06 AC 5 ms
6,584 KB
testcase_07 AC 4 ms
6,440 KB
testcase_08 AC 4 ms
6,640 KB
testcase_09 AC 4 ms
6,544 KB
testcase_10 AC 4 ms
6,640 KB
testcase_11 AC 10 ms
6,532 KB
testcase_12 AC 32 ms
6,620 KB
testcase_13 AC 29 ms
6,700 KB
testcase_14 AC 38 ms
6,772 KB
testcase_15 AC 4 ms
6,640 KB
testcase_16 AC 29 ms
6,716 KB
testcase_17 AC 4 ms
6,600 KB
testcase_18 AC 8 ms
6,584 KB
testcase_19 AC 32 ms
6,608 KB
testcase_20 AC 19 ms
6,664 KB
testcase_21 AC 24 ms
6,560 KB
testcase_22 AC 28 ms
6,608 KB
testcase_23 AC 28 ms
6,560 KB
testcase_24 AC 19 ms
6,612 KB
testcase_25 AC 19 ms
6,696 KB
testcase_26 AC 24 ms
6,628 KB
testcase_27 AC 24 ms
6,628 KB
testcase_28 AC 22 ms
6,760 KB
testcase_29 AC 37 ms
6,560 KB
testcase_30 AC 23 ms
6,720 KB
testcase_31 AC 29 ms
6,616 KB
testcase_32 AC 22 ms
6,772 KB
testcase_33 AC 29 ms
6,564 KB
testcase_34 AC 9 ms
6,556 KB
testcase_35 AC 21 ms
6,560 KB
testcase_36 AC 18 ms
6,564 KB
testcase_37 AC 10 ms
6,628 KB
testcase_38 AC 16 ms
6,676 KB
testcase_39 AC 6 ms
6,528 KB
testcase_40 AC 12 ms
6,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
using namespace atcoder;

#include <bits/stdc++.h>
using namespace std;

constexpr long long INF_LL = 2000000000000000000LL;
constexpr int INF = 1000000000;
constexpr long long MOD = 998244353;

#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;

int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};

template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

template <class T>
T gcd(T m, T n) {
    if(n == 0) return m;
    return gcd(n, m % n);
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

typedef vector<vector<edge>> graph;

using mint = modint998244353;
// using mint2 = modint1000000007;
// constexpr int MAX_COM = 100001;
// mint fac[MAX_COM], ifac[MAX_COM];
// void initfac() {
//     fac[0] = ifac[0] = 1;
//     REP(i, 1, MAX_COM) fac[i] = i * fac[i - 1];
//     REP(i, 1, MAX_COM) ifac[i] = 1 / fac[i];
// }
// mint nCr(int n, int r){
//     if(r < 0 || n < r) return 0;
//     return fac[n] * ifac[n - r] * ifac[r];
// }


// typedef int S;
// S op(S x, S y){ return x + y; }
// S e(){ return 0; }
// typedef int F;
// S mapping(F f, S x){ 
//     return f + x;
// }
// F composition(F f, F g){ 
//     return f + g;
// }
// F id(){ return 0; }

mint dp10[200010], dp11[200010], dp20[200010], dp21[200010];

void solve(){
    int n;
    string s;
    cin >> n >> s;
    dp10[0] = 1;
    rep(i, n){
        rep(j, 26){
            if(s[i] == 'a' + j){
                if(j == 0){
                    dp11[i + 1] += dp10[i];
                }else{
                    dp10[i + 1] += dp10[i];
                    dp11[i + 1] += dp11[i];
                }
            }else if(s[i] > 'a' + j){
                if(j == 0){
                    dp21[i + 1] += dp10[i];
                }else{
                    dp20[i + 1] += dp10[i];
                    dp21[i + 1] += dp11[i];
                }
            }
            if(j == 0){
                dp21[i + 1] += dp20[i];
            }else{
                dp20[i + 1] += dp20[i];
                dp21[i + 1] += dp21[i];
            }
        }
    }
    cout << (dp21[n]).val() << endl;
}

int main(){
    cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);

    // initfac();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
0