結果

問題 No.1702 count good string
ユーザー tenten
提出日時 2021-10-18 19:40:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 78,200 KB
実行使用メモリ 52,372 KB
最終ジャッジ日時 2024-09-19 15:49:39
合計ジャッジ時間 8,460 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 base = "yukicoder";
        int length = base.length();
        int[][] dp = new int[2][length + 1];
        dp[0][0] = 1;
        HashMap<Character, Integer> idxes = new HashMap<>();
        for (int i = 0; i < length; i++) {
            idxes.put(base.charAt(i), i + 1);
        }
        for (char c : sc.next().toCharArray()) {
            if (c == '?') {
                for (int i = 1; i <= length; i++) {
                    dp[1][i] += dp[0][i - 1];
                    dp[1][i] %= MOD;
                }
            } else if (idxes.containsKey(c)) {
                int x = idxes.get(c);
                dp[0][x] += dp[0][x - 1];
                dp[0][x] %= MOD;
                dp[1][x] += dp[1][x - 1];
                dp[1][x] %= MOD;
            }
        }
        System.out.println((dp[0][length] + dp[1][length]) % 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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0