結果
| 問題 |
No.1702 count good string
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-09 15:02:02 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 123 ms / 2,000 ms |
| コード長 | 1,893 bytes |
| コンパイル時間 | 2,192 ms |
| コンパイル使用メモリ | 78,260 KB |
| 実行使用メモリ | 39,776 KB |
| 最終ジャッジ日時 | 2024-11-18 13:01:59 |
| 合計ジャッジ時間 | 8,192 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
import java.util.*;
import java.io.*;
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();
HashMap<Character, Integer> idxes = new HashMap<>();
for (int i = 0; i < yukicoder.length; i++) {
idxes.put(yukicoder[i], i + 1);
}
int[][] dp = new int[yukicoder.length + 1][2];
dp[0][0] = 1;
for (char c : sc.next().toCharArray()) {
if (c == '?') {
for (int i = 1; i <= yukicoder.length; i++) {
dp[i][1] += dp[i - 1][0];
dp[i][1] %= MOD;
}
} else 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;
}
}
System.out.println((dp[yukicoder.length][0] + dp[yukicoder.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 nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten