結果

問題 No.1740 Alone 'a'
ユーザー tentententen
提出日時 2023-06-29 08:38:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 5,533 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 62,228 KB
最終ジャッジ日時 2023-09-20 04:16:42
合計ジャッジ時間 10,193 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,696 KB
testcase_01 AC 43 ms
49,528 KB
testcase_02 AC 43 ms
49,400 KB
testcase_03 AC 168 ms
62,228 KB
testcase_04 AC 171 ms
62,168 KB
testcase_05 AC 47 ms
49,400 KB
testcase_06 AC 46 ms
47,312 KB
testcase_07 AC 44 ms
49,680 KB
testcase_08 AC 43 ms
49,236 KB
testcase_09 AC 43 ms
49,292 KB
testcase_10 AC 44 ms
49,816 KB
testcase_11 AC 60 ms
49,680 KB
testcase_12 AC 126 ms
56,568 KB
testcase_13 AC 135 ms
57,436 KB
testcase_14 AC 149 ms
59,880 KB
testcase_15 AC 45 ms
47,988 KB
testcase_16 AC 120 ms
57,160 KB
testcase_17 AC 45 ms
49,352 KB
testcase_18 AC 58 ms
49,856 KB
testcase_19 AC 139 ms
57,424 KB
testcase_20 AC 88 ms
53,468 KB
testcase_21 AC 103 ms
56,412 KB
testcase_22 AC 129 ms
57,736 KB
testcase_23 AC 118 ms
56,920 KB
testcase_24 AC 96 ms
56,956 KB
testcase_25 AC 93 ms
55,996 KB
testcase_26 AC 105 ms
56,384 KB
testcase_27 AC 110 ms
57,204 KB
testcase_28 AC 97 ms
54,504 KB
testcase_29 AC 154 ms
61,692 KB
testcase_30 AC 116 ms
56,832 KB
testcase_31 AC 120 ms
57,160 KB
testcase_32 AC 99 ms
56,852 KB
testcase_33 AC 135 ms
57,932 KB
testcase_34 AC 60 ms
49,504 KB
testcase_35 AC 97 ms
56,744 KB
testcase_36 AC 93 ms
54,644 KB
testcase_37 AC 59 ms
50,480 KB
testcase_38 AC 86 ms
54,016 KB
testcase_39 AC 49 ms
49,436 KB
testcase_40 AC 63 ms
51,760 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 aCount = 0;
        for (int i = 1; i <= n; i++) {
            int idx = inputs[i - 1] - 'a';
            dp[i][0] = dp[i - 1][0] * 25 % MOD;
            dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 25) % MOD;
            if (idx == 0) {
                aCount++;
                continue;
            }
            if (aCount > 1) {
                continue;
            }
            if (aCount == 0) {
                dp[i][1]++;
                dp[i][1] %= MOD;
                dp[i][0] += idx - 1;
                dp[i][0] %= MOD;
            } else {
                dp[i][1] += idx - 1;
            }
            
        }
        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