結果
問題 | No.1740 Alone 'a' |
ユーザー | tenten |
提出日時 | 2023-04-13 10:56:17 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 181 ms / 2,000 ms |
コード長 | 2,345 bytes |
コンパイル時間 | 2,701 ms |
コンパイル使用メモリ | 88,416 KB |
実行使用メモリ | 51,476 KB |
最終ジャッジ日時 | 2024-10-09 09:54:04 |
合計ジャッジ時間 | 8,132 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
37,324 KB |
testcase_01 | AC | 54 ms
37,252 KB |
testcase_02 | AC | 53 ms
37,488 KB |
testcase_03 | AC | 154 ms
50,524 KB |
testcase_04 | AC | 181 ms
51,476 KB |
testcase_05 | AC | 58 ms
37,204 KB |
testcase_06 | AC | 58 ms
37,416 KB |
testcase_07 | AC | 54 ms
37,080 KB |
testcase_08 | AC | 53 ms
37,176 KB |
testcase_09 | AC | 56 ms
37,372 KB |
testcase_10 | AC | 54 ms
37,324 KB |
testcase_11 | AC | 74 ms
39,016 KB |
testcase_12 | AC | 137 ms
45,668 KB |
testcase_13 | AC | 122 ms
45,736 KB |
testcase_14 | AC | 167 ms
51,012 KB |
testcase_15 | AC | 55 ms
37,320 KB |
testcase_16 | AC | 131 ms
45,748 KB |
testcase_17 | AC | 55 ms
37,080 KB |
testcase_18 | AC | 68 ms
38,288 KB |
testcase_19 | AC | 138 ms
46,172 KB |
testcase_20 | AC | 99 ms
41,864 KB |
testcase_21 | AC | 116 ms
46,008 KB |
testcase_22 | AC | 131 ms
46,240 KB |
testcase_23 | AC | 137 ms
45,820 KB |
testcase_24 | AC | 101 ms
41,884 KB |
testcase_25 | AC | 103 ms
41,944 KB |
testcase_26 | AC | 117 ms
46,020 KB |
testcase_27 | AC | 121 ms
45,992 KB |
testcase_28 | AC | 108 ms
46,088 KB |
testcase_29 | AC | 164 ms
51,220 KB |
testcase_30 | AC | 122 ms
45,924 KB |
testcase_31 | AC | 129 ms
46,168 KB |
testcase_32 | AC | 112 ms
45,704 KB |
testcase_33 | AC | 144 ms
47,228 KB |
testcase_34 | AC | 73 ms
38,572 KB |
testcase_35 | AC | 108 ms
45,796 KB |
testcase_36 | AC | 92 ms
41,332 KB |
testcase_37 | AC | 72 ms
38,704 KB |
testcase_38 | AC | 88 ms
40,540 KB |
testcase_39 | AC | 60 ms
37,780 KB |
testcase_40 | AC | 77 ms
39,620 KB |
ソースコード
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(); } }