結果
問題 | No.2964 Obstruction Bingo |
ユーザー | ks2m |
提出日時 | 2024-11-16 16:55:17 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,171 bytes |
コンパイル時間 | 2,601 ms |
コンパイル使用メモリ | 79,924 KB |
実行使用メモリ | 113,408 KB |
最終ジャッジ日時 | 2024-11-16 16:57:50 |
合計ジャッジ時間 | 132,554 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 160 ms
47,344 KB |
testcase_01 | AC | 160 ms
99,460 KB |
testcase_02 | AC | 251 ms
52,576 KB |
testcase_03 | AC | 161 ms
47,216 KB |
testcase_04 | AC | 171 ms
47,652 KB |
testcase_05 | TLE | - |
testcase_06 | AC | 2,297 ms
61,916 KB |
testcase_07 | AC | 446 ms
105,420 KB |
testcase_08 | AC | 2,431 ms
61,436 KB |
testcase_09 | AC | 2,453 ms
113,392 KB |
testcase_10 | TLE | - |
testcase_11 | AC | 495 ms
106,948 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 2,277 ms
113,408 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 744 ms
112,588 KB |
testcase_16 | AC | 685 ms
60,740 KB |
testcase_17 | AC | 507 ms
106,444 KB |
testcase_18 | AC | 1,391 ms
60,672 KB |
testcase_19 | AC | 504 ms
105,628 KB |
testcase_20 | TLE | - |
testcase_21 | AC | 2,056 ms
113,196 KB |
testcase_22 | AC | 318 ms
52,788 KB |
testcase_23 | AC | 264 ms
52,036 KB |
testcase_24 | AC | 314 ms
52,152 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 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | TLE | - |
testcase_48 | TLE | - |
testcase_49 | TLE | - |
testcase_50 | TLE | - |
testcase_51 | TLE | - |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int k = sc.nextInt(); char[] s = sc.next().toCharArray(); char[] t = sc.next().toCharArray(); int[] a = new int[26]; int sum = 0; for (int i = 0; i < 26; i++) { a[i] = sc.nextInt(); sum += a[i]; } sc.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; } } long[][] dp = new long[k + 1][k + 1]; dp[0][0] = 1; long x = 0; long y = 0; for (int z = 0; z < k; z++) { long[][] wk = new long[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++) { for (int j = 0; j <= z + 1; j++) { if (i == j + l) { x += wk[i][j]; wk[i][j] = 0; } if (j == i + l) { y += wk[i][j]; wk[i][j] = 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; } }