結果

問題 No.1740 Alone 'a'
ユーザー ripityripity
提出日時 2021-11-12 22:36:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 585 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 4,609 ms
コンパイル使用メモリ 76,940 KB
実行使用メモリ 58,244 KB
最終ジャッジ日時 2024-05-04 10:01:33
合計ジャッジ時間 17,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
41,160 KB
testcase_01 AC 133 ms
41,592 KB
testcase_02 AC 133 ms
41,208 KB
testcase_03 AC 585 ms
57,944 KB
testcase_04 AC 582 ms
58,244 KB
testcase_05 AC 178 ms
42,084 KB
testcase_06 AC 178 ms
42,080 KB
testcase_07 AC 146 ms
41,252 KB
testcase_08 AC 134 ms
41,280 KB
testcase_09 AC 135 ms
41,568 KB
testcase_10 AC 137 ms
41,404 KB
testcase_11 AC 239 ms
47,944 KB
testcase_12 AC 482 ms
56,440 KB
testcase_13 AC 466 ms
56,552 KB
testcase_14 AC 502 ms
57,384 KB
testcase_15 AC 141 ms
40,664 KB
testcase_16 AC 461 ms
56,132 KB
testcase_17 AC 155 ms
41,528 KB
testcase_18 AC 201 ms
43,344 KB
testcase_19 AC 476 ms
56,516 KB
testcase_20 AC 347 ms
52,676 KB
testcase_21 AC 401 ms
52,644 KB
testcase_22 AC 448 ms
56,532 KB
testcase_23 AC 452 ms
56,656 KB
testcase_24 AC 348 ms
52,712 KB
testcase_25 AC 349 ms
52,716 KB
testcase_26 AC 388 ms
52,724 KB
testcase_27 AC 396 ms
52,712 KB
testcase_28 AC 373 ms
52,648 KB
testcase_29 AC 525 ms
57,572 KB
testcase_30 AC 398 ms
52,676 KB
testcase_31 AC 456 ms
56,480 KB
testcase_32 AC 373 ms
52,848 KB
testcase_33 AC 451 ms
56,788 KB
testcase_34 AC 210 ms
43,860 KB
testcase_35 AC 356 ms
52,464 KB
testcase_36 AC 336 ms
48,072 KB
testcase_37 AC 209 ms
43,964 KB
testcase_38 AC 294 ms
48,020 KB
testcase_39 AC 173 ms
41,852 KB
testcase_40 AC 247 ms
47,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int[][][] dp = new int[N][2][2];
        int mod = 998244353;
        for( int i = 0; i <= s[0]-'a'; i++ ) {
            int j = i == 0 ? 1 : 0;
            int k = i < s[0]-'a' ? 1 : 0;
            dp[0][j][k]++;
        }
        
        for( int i = 0; i < N-1; i++ ) {
            for( int j = 0; j <= 1; j++ ) {
                for( int k = 0; k <= 1; k++ ) {
                    int max = k == 1 ? 'z'-'a' : s[i+1]-'a';
                    for( int d = 0; d <= max; d++ ) {
                        int x = d == 0 ? 1 : 0;
                        int y = d < s[i+1]-'a' ? 1 : 0;
                        if( (j&x) == 1 ) continue;
                        dp[i+1][j|x][k|y] += dp[i][j][k];
                        dp[i+1][j|x][k|y] %= mod;
                    }
                }
            }
        }
        
        System.out.println(dp[N-1][1][1]);
        
    }
    
}
0