結果

問題 No.1702 count good string
ユーザー tenten
提出日時 2021-11-29 17:15:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,789 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 78,160 KB
実行使用メモリ 39,820 KB
最終ジャッジ日時 2024-07-02 12:55:32
合計ジャッジ時間 8,287 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0