結果
問題 | No.2964 Obstruction Bingo |
ユーザー | ks2m |
提出日時 | 2024-11-16 17:06:07 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,258 bytes |
コンパイル時間 | 2,551 ms |
コンパイル使用メモリ | 79,572 KB |
実行使用メモリ | 55,544 KB |
最終ジャッジ日時 | 2024-11-16 17:07:57 |
合計ジャッジ時間 | 96,633 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
39,556 KB |
testcase_01 | AC | 76 ms
37,916 KB |
testcase_02 | AC | 160 ms
43,048 KB |
testcase_03 | AC | 91 ms
38,336 KB |
testcase_04 | AC | 80 ms
39,328 KB |
testcase_05 | AC | 1,526 ms
50,968 KB |
testcase_06 | AC | 1,458 ms
50,680 KB |
testcase_07 | AC | 347 ms
46,080 KB |
testcase_08 | AC | 1,509 ms
51,040 KB |
testcase_09 | AC | 1,510 ms
51,632 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 386 ms
46,012 KB |
testcase_12 | AC | 1,960 ms
55,212 KB |
testcase_13 | AC | 1,426 ms
50,148 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 546 ms
46,404 KB |
testcase_16 | AC | 498 ms
46,424 KB |
testcase_17 | AC | 390 ms
46,260 KB |
testcase_18 | AC | 922 ms
47,848 KB |
testcase_19 | AC | 384 ms
46,400 KB |
testcase_20 | AC | 1,640 ms
52,416 KB |
testcase_21 | AC | 1,310 ms
49,016 KB |
testcase_22 | AC | 276 ms
45,752 KB |
testcase_23 | AC | 174 ms
43,336 KB |
testcase_24 | AC | 264 ms
45,592 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,037 ms
54,628 KB |
testcase_46 | TLE | - |
testcase_47 | AC | 1,973 ms
54,444 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[1][1]; dp[0][0] = 1; long x = 0; long y = 0; for (int z = 0; z < k; z++) { int[][] wk = new int[z + 2][z + 2]; 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 + l <= z + 1; 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; } }