結果

問題 No.1740 Alone 'a'
ユーザー CuriousFairy315CuriousFairy315
提出日時 2021-11-12 22:33:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 3,577 ms
コンパイル使用メモリ 75,792 KB
実行使用メモリ 63,280 KB
最終ジャッジ日時 2023-08-17 02:39:12
合計ジャッジ時間 13,998 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,660 KB
testcase_01 AC 124 ms
55,716 KB
testcase_02 AC 124 ms
55,808 KB
testcase_03 AC 269 ms
63,280 KB
testcase_04 AC 263 ms
62,756 KB
testcase_05 AC 142 ms
56,068 KB
testcase_06 AC 142 ms
55,544 KB
testcase_07 AC 129 ms
55,768 KB
testcase_08 AC 124 ms
55,708 KB
testcase_09 AC 125 ms
55,540 KB
testcase_10 AC 124 ms
56,188 KB
testcase_11 AC 186 ms
58,248 KB
testcase_12 AC 254 ms
63,160 KB
testcase_13 AC 255 ms
61,120 KB
testcase_14 AC 270 ms
63,060 KB
testcase_15 AC 131 ms
55,520 KB
testcase_16 AC 245 ms
60,912 KB
testcase_17 AC 129 ms
55,740 KB
testcase_18 AC 154 ms
55,748 KB
testcase_19 AC 259 ms
62,920 KB
testcase_20 AC 234 ms
60,932 KB
testcase_21 AC 250 ms
61,044 KB
testcase_22 AC 241 ms
61,892 KB
testcase_23 AC 259 ms
61,152 KB
testcase_24 AC 236 ms
60,908 KB
testcase_25 AC 238 ms
61,100 KB
testcase_26 AC 251 ms
60,812 KB
testcase_27 AC 247 ms
60,852 KB
testcase_28 AC 245 ms
61,104 KB
testcase_29 AC 272 ms
63,120 KB
testcase_30 AC 259 ms
60,848 KB
testcase_31 AC 265 ms
61,016 KB
testcase_32 AC 259 ms
61,224 KB
testcase_33 AC 261 ms
61,004 KB
testcase_34 AC 160 ms
57,540 KB
testcase_35 AC 234 ms
61,264 KB
testcase_36 AC 241 ms
61,092 KB
testcase_37 AC 158 ms
57,760 KB
testcase_38 AC 212 ms
58,072 KB
testcase_39 AC 150 ms
55,708 KB
testcase_40 AC 192 ms
58,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			char[] S = sc.next().toCharArray();
			final int MOD = 998_244_353;
			final int LESS = 0, EQUAL = 1;
			long[][][] dp = new long[2][2][N + 1];
			dp[EQUAL][0][0] = 1;
			for (int i = 0;i < N;++ i) {
				if (S[i] != 'a') {
					dp[EQUAL][0][i + 1] = dp[EQUAL][0][i];
					dp[EQUAL][1][i + 1] = dp[EQUAL][1][i];
				} else dp[EQUAL][1][i + 1] = dp[EQUAL][0][i];
				dp[LESS][0][i + 1] = dp[EQUAL][0][i] * Math.max(0, S[i] - 'b');
				dp[LESS][0][i + 1] += dp[LESS][0][i] * 25;
				dp[LESS][0][i + 1] %= MOD;
				if (S[i] != 'a') dp[LESS][1][i + 1] = dp[EQUAL][0][i];
				dp[LESS][1][i + 1] += dp[EQUAL][1][i] * Math.max(0, S[i] - 'b');
				dp[LESS][1][i + 1] += dp[LESS][0][i];
				dp[LESS][1][i + 1] += dp[LESS][1][i] * 25;
				dp[LESS][1][i + 1] %= MOD;
			}
			System.out.println(dp[LESS][1][N]);
		}
	}
}
0