結果

問題 No.1702 count good string
ユーザー tentententen
提出日時 2023-01-13 17:44:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 2,381 bytes
コンパイル時間 3,844 ms
コンパイル使用メモリ 88,128 KB
実行使用メモリ 53,064 KB
最終ジャッジ日時 2023-08-26 00:17:18
合計ジャッジ時間 10,259 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,516 KB
testcase_01 AC 44 ms
49,904 KB
testcase_02 AC 44 ms
49,392 KB
testcase_03 AC 45 ms
49,328 KB
testcase_04 AC 43 ms
49,400 KB
testcase_05 AC 44 ms
49,488 KB
testcase_06 AC 44 ms
49,388 KB
testcase_07 AC 44 ms
49,388 KB
testcase_08 AC 44 ms
49,616 KB
testcase_09 AC 44 ms
49,908 KB
testcase_10 AC 44 ms
49,460 KB
testcase_11 AC 44 ms
49,348 KB
testcase_12 AC 44 ms
49,812 KB
testcase_13 AC 110 ms
52,532 KB
testcase_14 AC 114 ms
52,252 KB
testcase_15 AC 110 ms
52,836 KB
testcase_16 AC 117 ms
52,668 KB
testcase_17 AC 115 ms
52,440 KB
testcase_18 AC 114 ms
52,916 KB
testcase_19 AC 115 ms
52,948 KB
testcase_20 AC 115 ms
52,576 KB
testcase_21 AC 115 ms
52,768 KB
testcase_22 AC 115 ms
52,632 KB
testcase_23 AC 47 ms
49,380 KB
testcase_24 AC 46 ms
49,444 KB
testcase_25 AC 46 ms
49,536 KB
testcase_26 AC 47 ms
49,908 KB
testcase_27 AC 47 ms
49,456 KB
testcase_28 AC 47 ms
49,488 KB
testcase_29 AC 47 ms
49,388 KB
testcase_30 AC 47 ms
49,400 KB
testcase_31 AC 47 ms
49,372 KB
testcase_32 AC 46 ms
49,524 KB
testcase_33 AC 104 ms
52,668 KB
testcase_34 AC 110 ms
52,664 KB
testcase_35 AC 110 ms
52,568 KB
testcase_36 AC 109 ms
53,032 KB
testcase_37 AC 109 ms
52,588 KB
testcase_38 AC 109 ms
52,944 KB
testcase_39 AC 111 ms
53,064 KB
testcase_40 AC 109 ms
50,360 KB
testcase_41 AC 110 ms
52,584 KB
testcase_42 AC 107 ms
52,740 KB
testcase_43 AC 100 ms
52,392 KB
testcase_44 AC 118 ms
52,956 KB
testcase_45 AC 44 ms
49,672 KB
testcase_46 AC 44 ms
49,432 KB
testcase_47 AC 44 ms
49,464 KB
testcase_48 AC 44 ms
49,496 KB
testcase_49 AC 43 ms
49,800 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();
        int length = yukicoder.length;
        HashMap<Character, Integer> conv = new HashMap<>();
        for (int i = 0; i < length; i++) {
            conv.put(yukicoder[i], i + 1);
        }
        int[] dp1 = new int[length + 1];
        dp1[0] = 1;
        int[] dp2 = new int[length + 1];
        for (char c : sc.next().toCharArray()) {
            if (c == '?') {
                for (int i = length; i >= 1; i--) {
                    dp2[i] += dp1[i - 1];
                    dp2[i] %= MOD;
                }
            } else if (conv.containsKey(c)) {
                int idx = conv.get(c);
                dp1[idx] += dp1[idx - 1];
                dp1[idx] %= MOD;
                dp2[idx] += dp2[idx - 1];
                dp2[idx] %= MOD;
            }
        }
        System.out.println((dp1[length] + dp2[length]) % 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