結果

問題 No.1740 Alone 'a'
ユーザー tentententen
提出日時 2022-09-07 09:18:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,655 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 77,292 KB
実行使用メモリ 51,084 KB
最終ジャッジ日時 2024-05-02 02:05:42
合計ジャッジ時間 8,002 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
36,864 KB
testcase_01 AC 56 ms
36,624 KB
testcase_02 AC 55 ms
36,792 KB
testcase_03 AC 185 ms
50,436 KB
testcase_04 AC 184 ms
51,084 KB
testcase_05 AC 60 ms
37,220 KB
testcase_06 AC 56 ms
37,168 KB
testcase_07 AC 53 ms
37,048 KB
testcase_08 AC 54 ms
36,576 KB
testcase_09 AC 54 ms
36,772 KB
testcase_10 AC 53 ms
36,856 KB
testcase_11 AC 75 ms
38,828 KB
testcase_12 AC 136 ms
45,688 KB
testcase_13 AC 133 ms
45,800 KB
testcase_14 AC 151 ms
50,012 KB
testcase_15 AC 56 ms
36,956 KB
testcase_16 AC 134 ms
45,608 KB
testcase_17 AC 55 ms
36,664 KB
testcase_18 AC 70 ms
37,684 KB
testcase_19 AC 134 ms
45,484 KB
testcase_20 AC 97 ms
41,036 KB
testcase_21 AC 119 ms
45,432 KB
testcase_22 AC 121 ms
45,256 KB
testcase_23 AC 126 ms
45,372 KB
testcase_24 AC 96 ms
41,528 KB
testcase_25 AC 102 ms
41,676 KB
testcase_26 AC 119 ms
45,640 KB
testcase_27 AC 124 ms
45,688 KB
testcase_28 AC 111 ms
45,636 KB
testcase_29 AC 142 ms
49,932 KB
testcase_30 AC 119 ms
45,476 KB
testcase_31 AC 128 ms
45,444 KB
testcase_32 AC 119 ms
45,416 KB
testcase_33 AC 118 ms
45,368 KB
testcase_34 AC 70 ms
38,120 KB
testcase_35 AC 114 ms
45,208 KB
testcase_36 AC 89 ms
41,104 KB
testcase_37 AC 72 ms
38,020 KB
testcase_38 AC 86 ms
40,368 KB
testcase_39 AC 61 ms
37,292 KB
testcase_40 AC 76 ms
39,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[] input = sc.next().toCharArray();
        long[][] dp = new long[n + 1][2];
        int aCount = 0;
        for (int i = 1; i <= n; i++) {
            dp[i][0] = dp[i - 1][0] * 25 % MOD;
            dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 25) % MOD;
            if (input[i - 1] == 'a') {
                aCount++;
                continue;
            }
            if (aCount >= 2) {
                continue;
            }
            dp[i][aCount] += input[i - 1] - 'b';
            dp[i][aCount] %= MOD;
            if (aCount == 0) {
                dp[i][1]++;
                dp[i][1] %= MOD;
            }
        }
        System.out.println(dp[n][1]);
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0