結果

問題 No.1702 count good string
ユーザー neko_the_shadowneko_the_shadow
提出日時 2021-10-10 02:35:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 679 ms / 2,000 ms
コード長 3,636 bytes
コンパイル時間 6,307 ms
コンパイル使用メモリ 93,480 KB
実行使用メモリ 115,084 KB
最終ジャッジ日時 2023-10-11 18:33:47
合計ジャッジ時間 25,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
37,588 KB
testcase_01 AC 81 ms
36,504 KB
testcase_02 AC 90 ms
37,724 KB
testcase_03 AC 90 ms
38,276 KB
testcase_04 AC 93 ms
38,448 KB
testcase_05 AC 86 ms
38,000 KB
testcase_06 AC 89 ms
37,328 KB
testcase_07 AC 89 ms
37,404 KB
testcase_08 AC 91 ms
37,312 KB
testcase_09 AC 80 ms
36,224 KB
testcase_10 AC 87 ms
36,484 KB
testcase_11 AC 93 ms
37,368 KB
testcase_12 AC 92 ms
39,344 KB
testcase_13 AC 634 ms
95,252 KB
testcase_14 AC 630 ms
95,584 KB
testcase_15 AC 628 ms
95,416 KB
testcase_16 AC 636 ms
95,780 KB
testcase_17 AC 634 ms
95,748 KB
testcase_18 AC 679 ms
95,744 KB
testcase_19 AC 617 ms
97,584 KB
testcase_20 AC 621 ms
97,436 KB
testcase_21 AC 618 ms
97,404 KB
testcase_22 AC 604 ms
97,440 KB
testcase_23 AC 107 ms
44,352 KB
testcase_24 AC 107 ms
39,396 KB
testcase_25 AC 108 ms
39,756 KB
testcase_26 AC 108 ms
39,528 KB
testcase_27 AC 106 ms
39,132 KB
testcase_28 AC 107 ms
39,428 KB
testcase_29 AC 103 ms
39,432 KB
testcase_30 AC 108 ms
39,520 KB
testcase_31 AC 110 ms
39,544 KB
testcase_32 AC 106 ms
39,216 KB
testcase_33 AC 608 ms
96,512 KB
testcase_34 AC 603 ms
111,724 KB
testcase_35 AC 600 ms
111,236 KB
testcase_36 AC 603 ms
110,400 KB
testcase_37 AC 599 ms
110,780 KB
testcase_38 AC 605 ms
109,860 KB
testcase_39 AC 612 ms
110,080 KB
testcase_40 AC 601 ms
110,956 KB
testcase_41 AC 604 ms
110,600 KB
testcase_42 AC 605 ms
110,656 KB
testcase_43 AC 500 ms
108,928 KB
testcase_44 AC 514 ms
115,084 KB
testcase_45 AC 91 ms
53,540 KB
testcase_46 AC 91 ms
53,328 KB
testcase_47 AC 91 ms
53,556 KB
testcase_48 AC 91 ms
53,496 KB
testcase_49 AC 91 ms
53,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package _1702;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    int n;
    String s;
    String t;
    long[][] memo;
    long mod = 1000000000 + 7;
    
    public void exec() {
        n = stdin.nextInt();
        s = stdin.nextString();
        
        long ans = 0;
        String yuki = "yukicoder";
        
        t = "yukicoder";
        newMemo();
        ans += f(0, 0);
        ans %= mod;
        
        for (int i = 0; i < t.length(); i++) {
            t = yuki.substring(0, i) + "?" + yuki.substring(i+1);
            newMemo();
            ans += f(0, 0);
            ans %= mod;
        }
        
        stdout.println(ans);
    }
    
    private long f(int p, int q) {
        if (q == t.length()) return 1;
        if (p == s.length()) return 0;
        
        if (memo[p][q]!=-1) return memo[p][q];
        
        long ans = 0;
        if (s.charAt(p) == t.charAt(q)) {
            ans += f(p+1, q+1);
            ans %= mod;
        }
        ans += f(p+1, q);
        ans %= mod;
        
        memo[p][q] = ans;
        return ans;
    }
    
    private void newMemo() {
        memo = new long[s.length()][t.length()];
        for (long[] row : memo) Arrays.fill(row, -1);
    }

    private static final Stdin stdin = new Stdin(System.in);
    private static final Stdout stdout = new Stdout(System.out);

    public static void main(String[] args) {
        try {
            new Main().exec();
        } finally {
            stdout.flush();
        }
    }

    public static class Stdin {
        private Deque<String> queue;
        private BufferedReader in;
        private Pattern space;

        public Stdin(InputStream in) {
            this.queue = new ArrayDeque<>();
            this.in = new BufferedReader(new InputStreamReader(in));
            this.space = Pattern.compile(" ");
        }

        public String nextString() {
            if (queue.isEmpty()) {
                try {
                    String line = in.readLine();
                    if (line == null) {
                        throw new EOFException();
                    }
                    space.splitAsStream(line).forEach(this.queue::addLast);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return queue.removeFirst();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public double nextDouble() {
            return Double.parseDouble(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }
        
        public BigInteger nextBigInteger() {
            return new BigInteger(nextString());
        }
    }

    public static class Stdout {
        private PrintWriter stdout;

        public Stdout(PrintStream stdout) {
            this.stdout =  new PrintWriter(stdout, false);
        }

        public void println(Object ... objs) {
            for (int i = 0, len = objs.length; i < len; i++) {
                stdout.print(objs[i]);
                if (i != len-1) stdout.print(' ');
            }
            stdout.println();
        }

        public void flush() {
            stdout.flush();
        }
    }
}
0