結果

問題 No.1702 count good string
ユーザー tentententen
提出日時 2023-11-30 16:29:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 2,368 bytes
コンパイル時間 3,113 ms
コンパイル使用メモリ 92,056 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-11-30 16:30:01
合計ジャッジ時間 9,737 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
54,008 KB
testcase_01 AC 51 ms
54,000 KB
testcase_02 AC 53 ms
53,968 KB
testcase_03 AC 52 ms
51,924 KB
testcase_04 AC 52 ms
54,004 KB
testcase_05 AC 53 ms
53,980 KB
testcase_06 AC 54 ms
53,960 KB
testcase_07 AC 56 ms
54,000 KB
testcase_08 AC 53 ms
54,004 KB
testcase_09 AC 53 ms
53,996 KB
testcase_10 AC 51 ms
52,060 KB
testcase_11 AC 51 ms
53,956 KB
testcase_12 AC 52 ms
53,996 KB
testcase_13 AC 121 ms
55,924 KB
testcase_14 AC 119 ms
55,780 KB
testcase_15 AC 127 ms
56,036 KB
testcase_16 AC 118 ms
55,848 KB
testcase_17 AC 124 ms
54,252 KB
testcase_18 AC 116 ms
55,800 KB
testcase_19 AC 140 ms
55,836 KB
testcase_20 AC 124 ms
56,028 KB
testcase_21 AC 122 ms
56,048 KB
testcase_22 AC 123 ms
56,084 KB
testcase_23 AC 60 ms
54,004 KB
testcase_24 AC 55 ms
54,004 KB
testcase_25 AC 53 ms
53,984 KB
testcase_26 AC 56 ms
53,976 KB
testcase_27 AC 55 ms
53,992 KB
testcase_28 AC 52 ms
54,016 KB
testcase_29 AC 52 ms
54,028 KB
testcase_30 AC 52 ms
54,028 KB
testcase_31 AC 54 ms
52,084 KB
testcase_32 AC 59 ms
54,016 KB
testcase_33 AC 115 ms
55,796 KB
testcase_34 AC 113 ms
55,804 KB
testcase_35 AC 113 ms
55,716 KB
testcase_36 AC 120 ms
55,848 KB
testcase_37 AC 107 ms
56,060 KB
testcase_38 AC 116 ms
55,900 KB
testcase_39 AC 106 ms
55,796 KB
testcase_40 AC 110 ms
55,824 KB
testcase_41 AC 126 ms
55,932 KB
testcase_42 AC 113 ms
55,836 KB
testcase_43 AC 102 ms
55,532 KB
testcase_44 AC 123 ms
56,080 KB
testcase_45 AC 56 ms
53,992 KB
testcase_46 AC 54 ms
54,016 KB
testcase_47 AC 54 ms
54,024 KB
testcase_48 AC 54 ms
53,980 KB
testcase_49 AC 52 ms
53,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        char[] yukicoder = "yukicoder".toCharArray();
        HashMap<Character, Integer> idxes = new HashMap<>();
        for (int i = 0; i < yukicoder.length; i++) {
            idxes.put(yukicoder[i], i + 1);
        }
        int[][] dp = new int[yukicoder.length + 1][2];
        dp[0][0] = 1;
        for (char c : sc.next().toCharArray()) {
            if (c == '?') {
                for (int i = 1; i <= yukicoder.length; i++) {
                    dp[i][1] += dp[i - 1][0];
                    dp[i][1] %= MOD;
                }
            } else if (idxes.containsKey(c)) {
                int x = idxes.get(c);
                dp[x][0] += dp[x - 1][0];
                dp[x][0] %= MOD;
                dp[x][1] += dp[x - 1][1];
                dp[x][1] %= MOD;
            }
        }
        System.out.println((dp[yukicoder.length][0] + dp[yukicoder.length][1]) % MOD);
    }
}
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