結果

問題 No.1740 Alone 'a'
ユーザー tentententen
提出日時 2023-04-13 10:56:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 2,345 bytes
コンパイル時間 3,337 ms
コンパイル使用メモリ 92,308 KB
実行使用メモリ 62,000 KB
最終ジャッジ日時 2024-04-17 15:50:02
合計ジャッジ時間 6,527 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
50,384 KB
testcase_01 AC 44 ms
50,164 KB
testcase_02 AC 43 ms
50,392 KB
testcase_03 AC 122 ms
61,080 KB
testcase_04 AC 123 ms
61,412 KB
testcase_05 AC 47 ms
50,196 KB
testcase_06 AC 46 ms
50,452 KB
testcase_07 AC 44 ms
50,376 KB
testcase_08 AC 44 ms
50,572 KB
testcase_09 AC 44 ms
50,404 KB
testcase_10 AC 43 ms
50,140 KB
testcase_11 AC 61 ms
50,968 KB
testcase_12 AC 107 ms
56,752 KB
testcase_13 AC 107 ms
56,728 KB
testcase_14 AC 144 ms
61,820 KB
testcase_15 AC 46 ms
50,336 KB
testcase_16 AC 98 ms
56,428 KB
testcase_17 AC 44 ms
50,364 KB
testcase_18 AC 54 ms
50,508 KB
testcase_19 AC 107 ms
57,140 KB
testcase_20 AC 81 ms
53,600 KB
testcase_21 AC 99 ms
56,596 KB
testcase_22 AC 100 ms
57,152 KB
testcase_23 AC 100 ms
56,580 KB
testcase_24 AC 75 ms
53,236 KB
testcase_25 AC 72 ms
53,320 KB
testcase_26 AC 96 ms
56,632 KB
testcase_27 AC 95 ms
56,740 KB
testcase_28 AC 90 ms
56,564 KB
testcase_29 AC 135 ms
62,000 KB
testcase_30 AC 102 ms
56,812 KB
testcase_31 AC 107 ms
56,988 KB
testcase_32 AC 94 ms
56,536 KB
testcase_33 AC 107 ms
56,772 KB
testcase_34 AC 63 ms
50,712 KB
testcase_35 AC 96 ms
56,620 KB
testcase_36 AC 79 ms
54,036 KB
testcase_37 AC 61 ms
51,024 KB
testcase_38 AC 82 ms
53,672 KB
testcase_39 AC 50 ms
50,288 KB
testcase_40 AC 63 ms
53,060 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();
        int count = 0;
        long[][] dp = new long[n + 1][2];
        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;
            int current = inputs[i - 1] - 'a';
            if (current > 0) {
                current--;
            }
            if (count == 0) {
                dp[i][0] += current;
                dp[i][0] %= MOD;
                if (inputs[i - 1] > 'a') {
                    dp[i][1]++;
                    dp[i][1] %= MOD;
                }
            } else if (count == 1) {
                dp[i][1] += current;
                dp[i][1] %= MOD;
            }
            if (inputs[i - 1] == 'a') {
                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