結果

問題 No.1740 Alone 'a'
ユーザー tentententen
提出日時 2021-11-15 12:41:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 4,240 ms
コンパイル使用メモリ 74,584 KB
実行使用メモリ 78,412 KB
最終ジャッジ日時 2023-08-21 03:54:27
合計ジャッジ時間 11,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,320 KB
testcase_01 AC 43 ms
49,440 KB
testcase_02 AC 43 ms
49,852 KB
testcase_03 AC 238 ms
78,412 KB
testcase_04 AC 231 ms
78,340 KB
testcase_05 AC 49 ms
49,744 KB
testcase_06 AC 48 ms
49,684 KB
testcase_07 AC 45 ms
49,808 KB
testcase_08 AC 45 ms
49,404 KB
testcase_09 AC 43 ms
49,752 KB
testcase_10 AC 43 ms
49,448 KB
testcase_11 AC 74 ms
54,844 KB
testcase_12 AC 209 ms
67,128 KB
testcase_13 AC 177 ms
65,212 KB
testcase_14 AC 216 ms
71,020 KB
testcase_15 AC 46 ms
49,344 KB
testcase_16 AC 215 ms
66,512 KB
testcase_17 AC 45 ms
49,920 KB
testcase_18 AC 62 ms
52,460 KB
testcase_19 AC 214 ms
66,740 KB
testcase_20 AC 119 ms
60,992 KB
testcase_21 AC 143 ms
61,468 KB
testcase_22 AC 178 ms
65,096 KB
testcase_23 AC 197 ms
66,480 KB
testcase_24 AC 121 ms
61,312 KB
testcase_25 AC 117 ms
60,420 KB
testcase_26 AC 136 ms
61,444 KB
testcase_27 AC 160 ms
65,316 KB
testcase_28 AC 119 ms
61,164 KB
testcase_29 AC 210 ms
69,080 KB
testcase_30 AC 161 ms
65,608 KB
testcase_31 AC 196 ms
66,892 KB
testcase_32 AC 129 ms
61,760 KB
testcase_33 AC 193 ms
66,732 KB
testcase_34 AC 64 ms
49,668 KB
testcase_35 AC 123 ms
58,920 KB
testcase_36 AC 119 ms
61,128 KB
testcase_37 AC 64 ms
52,756 KB
testcase_38 AC 94 ms
54,964 KB
testcase_39 AC 52 ms
49,356 KB
testcase_40 AC 75 ms
54,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        char[] values = sc.next().toCharArray();
        long[][][] dp = new long[n + 1][2][2];
        dp[0][0][0] = 1;
        for (int i = 1; i <= n; i++) {
            if (values[i - 1] == 'a') {
                dp[i][1][0] = dp[i - 1][0][0];
                dp[i][0][1] = (dp[i - 1][0][1] * 25) % MOD;
                dp[i][1][1] = (dp[i - 1][1][1] * 25 + dp[i - 1][0][1]) % MOD;
            } else {
                dp[i][0][0] = dp[i - 1][0][0];
                dp[i][1][0] = dp[i - 1][1][0];
                dp[i][0][1] = (dp[i - 1][0][1] * 25 + dp[i - 1][0][0] * (values[i - 1] - 'b')) % MOD;
                dp[i][1][1] = (dp[i - 1][1][1] * 25 + dp[i - 1][0][1] + dp[i - 1][1][0] * (values[i - 1] - 'b') + dp[i - 1][0][0]) % MOD;
            }
        }
        System.out.println(dp[n][1][1]);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0