結果
| 問題 | No.1702 count good string |
| コンテスト | |
| ユーザー |
merlin
|
| 提出日時 | 2021-10-08 22:20:48 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 123 ms / 2,000 ms |
| コード長 | 1,112 bytes |
| コンパイル時間 | 2,269 ms |
| コンパイル使用メモリ | 78,152 KB |
| 実行使用メモリ | 52,628 KB |
| 最終ジャッジ日時 | 2024-07-23 04:51:50 |
| 合計ジャッジ時間 | 7,557 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 |
ソースコード
import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
int n=Integer.parseInt(bu.readLine());
char s[]=bu.readLine().toCharArray();
HashMap<Character,Integer> mp=new HashMap<>();
String x="yukicoder";
int i,l=x.length();
for(i=0;i<l;i++) mp.put(x.charAt(i),i+1);
mp.put('?',0);
long dp[][]=new long[2][l+1],M=(int)1e9+7;
dp[0][0]=1; //use this only for non ? marks
for(i=0;i<n;i++)
if(mp.get(s[i])!=null)
{
int in=mp.get(s[i]);
if(in>0) //all subsequences which either have a ? or dont
{
dp[0][in]=(dp[0][in]+dp[0][in-1])%M;
dp[1][in]=(dp[1][in]+dp[1][in-1])%M;
}
else //we can use at most 1 ?
for(int j=l;j>0;j--) dp[1][j]=(dp[0][j-1]+dp[1][j])%M;
}
System.out.println((dp[0][l]+dp[1][l])%M);
}
}
merlin