結果

問題 No.1740 Alone 'a'
ユーザー ripityripity
提出日時 2021-11-12 22:36:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 586 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 1,882 ms
コンパイル使用メモリ 73,920 KB
実行使用メモリ 72,120 KB
最終ジャッジ日時 2023-08-17 02:48:34
合計ジャッジ時間 15,998 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
55,424 KB
testcase_01 AC 116 ms
56,092 KB
testcase_02 AC 114 ms
55,716 KB
testcase_03 AC 586 ms
72,120 KB
testcase_04 AC 569 ms
72,112 KB
testcase_05 AC 160 ms
56,028 KB
testcase_06 AC 153 ms
56,448 KB
testcase_07 AC 124 ms
55,992 KB
testcase_08 AC 119 ms
55,672 KB
testcase_09 AC 116 ms
55,908 KB
testcase_10 AC 115 ms
55,832 KB
testcase_11 AC 215 ms
60,500 KB
testcase_12 AC 475 ms
68,700 KB
testcase_13 AC 457 ms
69,020 KB
testcase_14 AC 496 ms
69,736 KB
testcase_15 AC 138 ms
55,756 KB
testcase_16 AC 451 ms
68,528 KB
testcase_17 AC 136 ms
55,836 KB
testcase_18 AC 182 ms
57,560 KB
testcase_19 AC 475 ms
69,420 KB
testcase_20 AC 313 ms
65,536 KB
testcase_21 AC 386 ms
66,632 KB
testcase_22 AC 435 ms
69,352 KB
testcase_23 AC 427 ms
69,292 KB
testcase_24 AC 329 ms
66,096 KB
testcase_25 AC 337 ms
66,124 KB
testcase_26 AC 362 ms
65,816 KB
testcase_27 AC 384 ms
66,168 KB
testcase_28 AC 349 ms
66,412 KB
testcase_29 AC 511 ms
67,536 KB
testcase_30 AC 388 ms
66,108 KB
testcase_31 AC 451 ms
69,212 KB
testcase_32 AC 349 ms
66,276 KB
testcase_33 AC 440 ms
68,704 KB
testcase_34 AC 190 ms
58,008 KB
testcase_35 AC 330 ms
65,964 KB
testcase_36 AC 317 ms
65,804 KB
testcase_37 AC 193 ms
57,984 KB
testcase_38 AC 288 ms
61,348 KB
testcase_39 AC 162 ms
55,700 KB
testcase_40 AC 248 ms
60,828 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