結果

問題 No.1702 count good string
ユーザー tentententen
提出日時 2023-03-27 13:36:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 2,465 bytes
コンパイル時間 2,666 ms
コンパイル使用メモリ 87,832 KB
実行使用メモリ 39,232 KB
最終ジャッジ日時 2023-10-19 14:06:07
合計ジャッジ時間 9,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
36,708 KB
testcase_01 AC 51 ms
36,732 KB
testcase_02 AC 51 ms
36,720 KB
testcase_03 AC 50 ms
36,752 KB
testcase_04 AC 50 ms
36,740 KB
testcase_05 AC 51 ms
36,716 KB
testcase_06 AC 51 ms
36,712 KB
testcase_07 AC 51 ms
36,688 KB
testcase_08 AC 51 ms
36,716 KB
testcase_09 AC 52 ms
36,724 KB
testcase_10 AC 51 ms
36,716 KB
testcase_11 AC 51 ms
36,768 KB
testcase_12 AC 51 ms
36,688 KB
testcase_13 AC 124 ms
38,780 KB
testcase_14 AC 125 ms
39,048 KB
testcase_15 AC 128 ms
39,008 KB
testcase_16 AC 128 ms
39,232 KB
testcase_17 AC 124 ms
39,008 KB
testcase_18 AC 119 ms
38,928 KB
testcase_19 AC 128 ms
38,960 KB
testcase_20 AC 128 ms
39,088 KB
testcase_21 AC 125 ms
38,968 KB
testcase_22 AC 125 ms
39,016 KB
testcase_23 AC 52 ms
36,736 KB
testcase_24 AC 53 ms
36,720 KB
testcase_25 AC 52 ms
36,720 KB
testcase_26 AC 52 ms
36,724 KB
testcase_27 AC 52 ms
36,748 KB
testcase_28 AC 52 ms
36,740 KB
testcase_29 AC 57 ms
36,708 KB
testcase_30 AC 54 ms
36,748 KB
testcase_31 AC 52 ms
36,704 KB
testcase_32 AC 53 ms
36,780 KB
testcase_33 AC 122 ms
38,936 KB
testcase_34 AC 120 ms
38,940 KB
testcase_35 AC 123 ms
39,008 KB
testcase_36 AC 123 ms
38,912 KB
testcase_37 AC 122 ms
39,228 KB
testcase_38 AC 119 ms
38,908 KB
testcase_39 AC 111 ms
38,964 KB
testcase_40 AC 123 ms
38,684 KB
testcase_41 AC 121 ms
39,172 KB
testcase_42 AC 123 ms
39,224 KB
testcase_43 AC 115 ms
38,616 KB
testcase_44 AC 134 ms
39,220 KB
testcase_45 AC 51 ms
36,712 KB
testcase_46 AC 52 ms
36,716 KB
testcase_47 AC 53 ms
36,712 KB
testcase_48 AC 52 ms
36,716 KB
testcase_49 AC 50 ms
36,724 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[] inputs = sc.next().toCharArray();
        char[] yukicoder = "yukicoder".toCharArray();
        HashMap<Character, Integer> idxes = new HashMap<>();
        for (int i = 0; i < yukicoder.length; i++) {
            idxes.put(yukicoder[i], i);
        }
        int length = yukicoder.length;
        int[] dp1 = new int[length + 1];
        int[] dp2 = new int[length + 1];
        dp1[0] = 1;
        dp2[0] = 1;
        for (char c : inputs) {
            if (c == '?') {
                for (int i = length; i > 0; i--) {
                    dp1[i] += dp2[i - 1];
                    dp1[i] %= MOD;
                }
            } else {
                if (idxes.containsKey(c)) {
                    int x = idxes.get(c) + 1;
                    dp1[x] += dp1[x - 1];
                    dp1[x] %= MOD;
                    dp2[x] += dp2[x - 1];
                    dp2[x] %= MOD;
                }
            }
        }
        System.out.println(dp1[length]);
    }
}
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