結果

問題 No.1702 count good string
ユーザー merlinmerlin
提出日時 2021-10-08 22:20:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 75,628 KB
実行使用メモリ 52,980 KB
最終ジャッジ日時 2023-09-30 10:44:58
合計ジャッジ時間 8,684 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,512 KB
testcase_01 AC 42 ms
49,544 KB
testcase_02 AC 42 ms
49,260 KB
testcase_03 AC 46 ms
49,148 KB
testcase_04 AC 43 ms
49,220 KB
testcase_05 AC 42 ms
49,468 KB
testcase_06 AC 42 ms
47,116 KB
testcase_07 AC 43 ms
49,236 KB
testcase_08 AC 42 ms
49,300 KB
testcase_09 AC 42 ms
49,180 KB
testcase_10 AC 42 ms
49,248 KB
testcase_11 AC 43 ms
49,336 KB
testcase_12 AC 41 ms
49,308 KB
testcase_13 AC 105 ms
52,492 KB
testcase_14 AC 105 ms
52,240 KB
testcase_15 AC 104 ms
52,276 KB
testcase_16 AC 106 ms
52,748 KB
testcase_17 AC 106 ms
52,672 KB
testcase_18 AC 109 ms
52,500 KB
testcase_19 AC 93 ms
52,468 KB
testcase_20 AC 105 ms
52,628 KB
testcase_21 AC 106 ms
52,732 KB
testcase_22 AC 107 ms
52,364 KB
testcase_23 AC 43 ms
49,268 KB
testcase_24 AC 47 ms
49,032 KB
testcase_25 AC 43 ms
49,064 KB
testcase_26 AC 43 ms
49,252 KB
testcase_27 AC 44 ms
49,368 KB
testcase_28 AC 44 ms
49,028 KB
testcase_29 AC 44 ms
49,268 KB
testcase_30 AC 44 ms
49,008 KB
testcase_31 AC 44 ms
49,424 KB
testcase_32 AC 43 ms
49,284 KB
testcase_33 AC 97 ms
52,436 KB
testcase_34 AC 98 ms
52,704 KB
testcase_35 AC 100 ms
52,524 KB
testcase_36 AC 98 ms
52,488 KB
testcase_37 AC 97 ms
52,208 KB
testcase_38 AC 97 ms
52,432 KB
testcase_39 AC 99 ms
52,980 KB
testcase_40 AC 96 ms
52,300 KB
testcase_41 AC 98 ms
51,912 KB
testcase_42 AC 100 ms
52,424 KB
testcase_43 AC 87 ms
52,040 KB
testcase_44 AC 113 ms
52,644 KB
testcase_45 AC 43 ms
49,512 KB
testcase_46 AC 42 ms
49,224 KB
testcase_47 AC 42 ms
49,320 KB
testcase_48 AC 41 ms
49,140 KB
testcase_49 AC 43 ms
49,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
    }
}
0