結果

問題 No.1702 count good string
ユーザー tentententen
提出日時 2023-04-26 08:35:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 2,452 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 86,660 KB
実行使用メモリ 52,480 KB
最終ジャッジ日時 2024-04-27 14:28:27
合計ジャッジ時間 8,623 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,372 KB
testcase_01 AC 50 ms
50,388 KB
testcase_02 AC 52 ms
49,984 KB
testcase_03 AC 54 ms
50,460 KB
testcase_04 AC 54 ms
50,236 KB
testcase_05 AC 56 ms
50,408 KB
testcase_06 AC 55 ms
50,308 KB
testcase_07 AC 56 ms
50,444 KB
testcase_08 AC 54 ms
50,336 KB
testcase_09 AC 54 ms
50,380 KB
testcase_10 AC 54 ms
50,348 KB
testcase_11 AC 54 ms
50,380 KB
testcase_12 AC 52 ms
50,320 KB
testcase_13 AC 124 ms
52,352 KB
testcase_14 AC 120 ms
52,288 KB
testcase_15 AC 122 ms
52,212 KB
testcase_16 AC 121 ms
52,188 KB
testcase_17 AC 131 ms
52,028 KB
testcase_18 AC 124 ms
52,312 KB
testcase_19 AC 126 ms
52,360 KB
testcase_20 AC 121 ms
52,480 KB
testcase_21 AC 121 ms
52,400 KB
testcase_22 AC 118 ms
52,472 KB
testcase_23 AC 52 ms
50,088 KB
testcase_24 AC 53 ms
50,016 KB
testcase_25 AC 53 ms
50,328 KB
testcase_26 AC 54 ms
50,360 KB
testcase_27 AC 53 ms
50,412 KB
testcase_28 AC 53 ms
50,396 KB
testcase_29 AC 54 ms
50,348 KB
testcase_30 AC 53 ms
50,472 KB
testcase_31 AC 55 ms
50,156 KB
testcase_32 AC 59 ms
50,172 KB
testcase_33 AC 119 ms
52,068 KB
testcase_34 AC 115 ms
52,084 KB
testcase_35 AC 113 ms
52,364 KB
testcase_36 AC 114 ms
52,216 KB
testcase_37 AC 119 ms
52,404 KB
testcase_38 AC 115 ms
52,060 KB
testcase_39 AC 116 ms
52,132 KB
testcase_40 AC 120 ms
52,352 KB
testcase_41 AC 115 ms
52,064 KB
testcase_42 AC 120 ms
52,348 KB
testcase_43 AC 98 ms
51,560 KB
testcase_44 AC 129 ms
52,252 KB
testcase_45 AC 53 ms
50,252 KB
testcase_46 AC 52 ms
50,152 KB
testcase_47 AC 51 ms
50,268 KB
testcase_48 AC 51 ms
50,224 KB
testcase_49 AC 51 ms
50,452 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 + 1);
        }
        int[][] counts = new int[yukicoder.length + 1][2];
        counts[0][0] = 1;
        for (char c : inputs) {
            if (idxes.containsKey(c)) {
                int i = idxes.get(c);
                counts[i][0] += counts[i - 1][0];
                counts[i][0] %= MOD;
                counts[i][1] += counts[i - 1][1];
                counts[i][1] %= MOD;
            } else if (c == '?') {
                for (int i = 1; i <= yukicoder.length; i++) {
                    counts[i][1] += counts[i - 1][0];
                    counts[i][1] %= MOD;
                }
            }
        }
        System.out.println((counts[yukicoder.length][0] + counts[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