結果
問題 | No.2964 Obstruction Bingo |
ユーザー | ks2m |
提出日時 | 2024-11-16 17:02:01 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,276 bytes |
コンパイル時間 | 2,617 ms |
コンパイル使用メモリ | 79,448 KB |
実行使用メモリ | 110,712 KB |
最終ジャッジ日時 | 2024-11-16 17:04:18 |
合計ジャッジ時間 | 105,299 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
39,268 KB |
testcase_01 | AC | 83 ms
37,860 KB |
testcase_02 | AC | 163 ms
45,160 KB |
testcase_03 | AC | 76 ms
38,048 KB |
testcase_04 | AC | 77 ms
38,140 KB |
testcase_05 | AC | 1,654 ms
54,868 KB |
testcase_06 | AC | 1,584 ms
54,936 KB |
testcase_07 | AC | 367 ms
45,816 KB |
testcase_08 | AC | 1,590 ms
54,704 KB |
testcase_09 | AC | 1,614 ms
54,916 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 404 ms
45,816 KB |
testcase_12 | AC | 2,140 ms
54,796 KB |
testcase_13 | AC | 1,477 ms
54,804 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 573 ms
46,416 KB |
testcase_16 | AC | 527 ms
46,128 KB |
testcase_17 | AC | 411 ms
45,804 KB |
testcase_18 | AC | 998 ms
54,052 KB |
testcase_19 | AC | 409 ms
45,752 KB |
testcase_20 | AC | 1,744 ms
54,828 KB |
testcase_21 | AC | 1,414 ms
54,928 KB |
testcase_22 | AC | 267 ms
45,584 KB |
testcase_23 | AC | 174 ms
45,188 KB |
testcase_24 | AC | 283 ms
45,528 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
testcase_45 | AC | 2,228 ms
54,812 KB |
testcase_46 | TLE | - |
testcase_47 | AC | 2,229 ms
54,860 KB |
testcase_48 | TLE | - |
testcase_49 | TLE | - |
testcase_50 | TLE | - |
testcase_51 | TLE | - |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int l = Integer.parseInt(sa[0]); int k = Integer.parseInt(sa[1]); char[] s = br.readLine().toCharArray(); char[] t = br.readLine().toCharArray(); sa = br.readLine().split(" "); int[] a = new int[26]; int sum = 0; for (int i = 0; i < 26; i++) { a[i] = Integer.parseInt(sa[i]); sum += a[i]; } br.close(); int mod = 998244353; long sm = modinv(sum, mod); long[] b = new long[26]; for (int i = 0; i < 26; i++) { b[i] = a[i] * sm % mod; } long[] b1 = new long[26]; for (int i = 0; i < 26; i++) { b1[i] = (sum - a[i]) * sm % mod; } long[][] b2 = new long[26][26]; for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { b2[i][j] = (sum - a[i] - a[j]) * sm % mod; } } int[][] dp = new int[k + 1][k + 1]; dp[0][0] = 1; long x = 0; long y = 0; for (int z = 0; z < k; z++) { int[][] wk = new int[k + 1][k + 1]; for (int i = 0; i <= z; i++) { for (int j = 0; j <= z; j++) { int p1 = i % l; int p2 = j % l; if (s[p1] == t[p2]) { int c = s[p1] - 'a'; wk[i + 1][j + 1] += dp[i][j] * b[c] % mod; wk[i + 1][j + 1] %= mod; wk[i][j] += dp[i][j] * b1[c] % mod; wk[i][j] %= mod; } else { int c1 = s[p1] - 'a'; wk[i + 1][j] += dp[i][j] * b[c1] % mod; wk[i + 1][j] %= mod; int c2 = t[p2] - 'a'; wk[i][j + 1] += dp[i][j] * b[c2] % mod; wk[i][j + 1] %= mod; wk[i][j] += dp[i][j] * b2[c1][c2] % mod; wk[i][j] %= mod; } } } for (int i = 0; i <= z + 1 && i + l <= k; i++) { x += wk[i + l][i]; wk[i + l][i] = 0; y += wk[i][i + l]; wk[i][i + l] = 0; } x %= mod; y %= mod; dp = wk; } System.out.println(x + " " + y); } static long modinv(long a, int m) { long b = m; long u = 1; long v = 0; long tmp = 0; while (b > 0) { long t = a / b; a -= t * b; tmp = a; a = b; b = tmp; u -= t * v; tmp = u; u = v; v = tmp; } u %= m; if (u < 0) u += m; return u; } }