結果
問題 | No.1702 count good string |
ユーザー | neko_the_shadow |
提出日時 | 2021-10-10 02:35:24 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 622 ms / 2,000 ms |
コード長 | 3,636 bytes |
コンパイル時間 | 8,263 ms |
コンパイル使用メモリ | 83,492 KB |
実行使用メモリ | 106,460 KB |
最終ジャッジ日時 | 2024-09-13 17:27:24 |
合計ジャッジ時間 | 21,997 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 107 ms
40,496 KB |
testcase_01 | AC | 96 ms
40,396 KB |
testcase_02 | AC | 97 ms
40,064 KB |
testcase_03 | AC | 102 ms
41,712 KB |
testcase_04 | AC | 103 ms
42,156 KB |
testcase_05 | AC | 96 ms
40,884 KB |
testcase_06 | AC | 105 ms
41,612 KB |
testcase_07 | AC | 99 ms
39,800 KB |
testcase_08 | AC | 106 ms
42,032 KB |
testcase_09 | AC | 95 ms
38,544 KB |
testcase_10 | AC | 96 ms
38,900 KB |
testcase_11 | AC | 107 ms
41,724 KB |
testcase_12 | AC | 99 ms
39,624 KB |
testcase_13 | AC | 620 ms
99,728 KB |
testcase_14 | AC | 620 ms
99,512 KB |
testcase_15 | AC | 617 ms
99,564 KB |
testcase_16 | AC | 611 ms
99,616 KB |
testcase_17 | AC | 605 ms
99,780 KB |
testcase_18 | AC | 622 ms
99,664 KB |
testcase_19 | AC | 614 ms
99,432 KB |
testcase_20 | AC | 617 ms
99,516 KB |
testcase_21 | AC | 610 ms
99,772 KB |
testcase_22 | AC | 614 ms
99,564 KB |
testcase_23 | AC | 108 ms
40,740 KB |
testcase_24 | AC | 109 ms
41,076 KB |
testcase_25 | AC | 114 ms
41,696 KB |
testcase_26 | AC | 110 ms
41,464 KB |
testcase_27 | AC | 113 ms
41,988 KB |
testcase_28 | AC | 109 ms
41,820 KB |
testcase_29 | AC | 109 ms
41,188 KB |
testcase_30 | AC | 114 ms
41,540 KB |
testcase_31 | AC | 115 ms
41,800 KB |
testcase_32 | AC | 110 ms
41,296 KB |
testcase_33 | AC | 601 ms
99,680 KB |
testcase_34 | AC | 597 ms
99,744 KB |
testcase_35 | AC | 595 ms
99,608 KB |
testcase_36 | AC | 597 ms
99,580 KB |
testcase_37 | AC | 601 ms
99,792 KB |
testcase_38 | AC | 601 ms
99,644 KB |
testcase_39 | AC | 593 ms
99,584 KB |
testcase_40 | AC | 596 ms
99,892 KB |
testcase_41 | AC | 598 ms
99,512 KB |
testcase_42 | AC | 601 ms
99,504 KB |
testcase_43 | AC | 514 ms
99,472 KB |
testcase_44 | AC | 517 ms
106,460 KB |
testcase_45 | AC | 90 ms
38,868 KB |
testcase_46 | AC | 95 ms
40,432 KB |
testcase_47 | AC | 98 ms
40,064 KB |
testcase_48 | AC | 99 ms
40,520 KB |
testcase_49 | AC | 104 ms
38,816 KB |
ソースコード
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(); } } }