結果
問題 | No.2964 Obstruction Bingo |
ユーザー | ks2m |
提出日時 | 2024-11-16 17:13:26 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 782 ms / 2,468 ms |
コード長 | 2,307 bytes |
コンパイル時間 | 3,099 ms |
コンパイル使用メモリ | 79,448 KB |
実行使用メモリ | 55,252 KB |
最終ジャッジ日時 | 2024-11-16 17:13:58 |
合計ジャッジ時間 | 29,440 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
37,536 KB |
testcase_01 | AC | 88 ms
39,612 KB |
testcase_02 | AC | 104 ms
41,360 KB |
testcase_03 | AC | 79 ms
39,572 KB |
testcase_04 | AC | 95 ms
38,604 KB |
testcase_05 | AC | 283 ms
49,716 KB |
testcase_06 | AC | 420 ms
50,216 KB |
testcase_07 | AC | 204 ms
46,788 KB |
testcase_08 | AC | 406 ms
50,660 KB |
testcase_09 | AC | 342 ms
51,528 KB |
testcase_10 | AC | 524 ms
54,512 KB |
testcase_11 | AC | 261 ms
45,140 KB |
testcase_12 | AC | 554 ms
54,236 KB |
testcase_13 | AC | 359 ms
50,276 KB |
testcase_14 | AC | 414 ms
54,364 KB |
testcase_15 | AC | 233 ms
46,332 KB |
testcase_16 | AC | 242 ms
45,296 KB |
testcase_17 | AC | 232 ms
45,888 KB |
testcase_18 | AC | 318 ms
46,900 KB |
testcase_19 | AC | 248 ms
45,856 KB |
testcase_20 | AC | 451 ms
51,956 KB |
testcase_21 | AC | 484 ms
48,176 KB |
testcase_22 | AC | 216 ms
44,880 KB |
testcase_23 | AC | 154 ms
42,932 KB |
testcase_24 | AC | 149 ms
46,320 KB |
testcase_25 | AC | 643 ms
54,456 KB |
testcase_26 | AC | 757 ms
54,480 KB |
testcase_27 | AC | 721 ms
54,432 KB |
testcase_28 | AC | 718 ms
54,524 KB |
testcase_29 | AC | 739 ms
54,508 KB |
testcase_30 | AC | 734 ms
54,276 KB |
testcase_31 | AC | 722 ms
54,244 KB |
testcase_32 | AC | 706 ms
54,372 KB |
testcase_33 | AC | 708 ms
54,504 KB |
testcase_34 | AC | 782 ms
54,308 KB |
testcase_35 | AC | 708 ms
54,336 KB |
testcase_36 | AC | 691 ms
54,464 KB |
testcase_37 | AC | 728 ms
54,492 KB |
testcase_38 | AC | 696 ms
54,392 KB |
testcase_39 | AC | 703 ms
55,220 KB |
testcase_40 | AC | 730 ms
54,304 KB |
testcase_41 | AC | 710 ms
54,360 KB |
testcase_42 | AC | 734 ms
54,460 KB |
testcase_43 | AC | 708 ms
54,584 KB |
testcase_44 | AC | 716 ms
55,168 KB |
testcase_45 | AC | 451 ms
54,948 KB |
testcase_46 | AC | 310 ms
54,436 KB |
testcase_47 | AC | 301 ms
54,052 KB |
testcase_48 | AC | 308 ms
54,580 KB |
testcase_49 | AC | 471 ms
55,252 KB |
testcase_50 | AC | 605 ms
55,164 KB |
testcase_51 | AC | 719 ms
54,584 KB |
ソースコード
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++) { if (dp[i][j] == 0) { continue; } 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; } }