結果

問題 No.1740 Alone 'a'
ユーザー tentententen
提出日時 2023-02-03 18:17:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 2,241 bytes
コンパイル時間 6,484 ms
コンパイル使用メモリ 87,652 KB
実行使用メモリ 47,892 KB
最終ジャッジ日時 2023-09-15 13:44:51
合計ジャッジ時間 9,587 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
37,236 KB
testcase_01 AC 40 ms
33,388 KB
testcase_02 AC 42 ms
33,376 KB
testcase_03 AC 190 ms
47,828 KB
testcase_04 AC 191 ms
47,892 KB
testcase_05 AC 43 ms
33,804 KB
testcase_06 AC 43 ms
33,924 KB
testcase_07 AC 40 ms
33,592 KB
testcase_08 AC 42 ms
33,824 KB
testcase_09 AC 38 ms
33,536 KB
testcase_10 AC 38 ms
33,460 KB
testcase_11 AC 60 ms
35,492 KB
testcase_12 AC 150 ms
43,884 KB
testcase_13 AC 122 ms
42,272 KB
testcase_14 AC 170 ms
47,892 KB
testcase_15 AC 41 ms
33,600 KB
testcase_16 AC 120 ms
42,508 KB
testcase_17 AC 41 ms
33,504 KB
testcase_18 AC 53 ms
34,536 KB
testcase_19 AC 150 ms
43,252 KB
testcase_20 AC 83 ms
38,196 KB
testcase_21 AC 106 ms
42,076 KB
testcase_22 AC 106 ms
42,744 KB
testcase_23 AC 117 ms
42,336 KB
testcase_24 AC 95 ms
42,448 KB
testcase_25 AC 97 ms
41,888 KB
testcase_26 AC 105 ms
42,216 KB
testcase_27 AC 106 ms
42,060 KB
testcase_28 AC 98 ms
42,064 KB
testcase_29 AC 141 ms
46,800 KB
testcase_30 AC 107 ms
42,212 KB
testcase_31 AC 122 ms
42,216 KB
testcase_32 AC 104 ms
42,184 KB
testcase_33 AC 123 ms
42,244 KB
testcase_34 AC 57 ms
34,748 KB
testcase_35 AC 96 ms
42,588 KB
testcase_36 AC 80 ms
38,076 KB
testcase_37 AC 57 ms
35,140 KB
testcase_38 AC 74 ms
37,384 KB
testcase_39 AC 45 ms
33,840 KB
testcase_40 AC 62 ms
35,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[] inputs = sc.next().toCharArray();
        long[][] dp = new long[n + 1][2];
        int count = 0;
        for (int i = 1; i <= n; i++) {
            dp[i][0] += dp[i - 1][0] * 25 % MOD;
            dp[i][0] %= MOD;
            dp[i][1] += (dp[i - 1][0] + dp[i - 1][1] * 25 % MOD) % MOD;
            dp[i][1] %= MOD;
            if (count > 1) {
                continue;
            }
            if (inputs[i - 1] > 'a') {
                dp[i][count] += inputs[i - 1] - 'b';
                dp[i][count] %= MOD;
                if (count == 0) {
                    dp[i][1]++;
                    dp[i][1] %= MOD;
                }
            } else {
                count++;
            }
        }
        System.out.println(dp[n][1]);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0