結果
問題 | No.2164 Equal Balls |
ユーザー | chro_96 |
提出日時 | 2022-12-15 01:50:02 |
言語 | C (gcc 12.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,882 bytes |
コンパイル時間 | 776 ms |
コンパイル使用メモリ | 33,856 KB |
実行使用メモリ | 286,080 KB |
最終ジャッジ日時 | 2024-11-08 18:29:21 |
合計ジャッジ時間 | 17,560 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 680 ms
281,088 KB |
testcase_01 | AC | 663 ms
281,088 KB |
testcase_02 | AC | 1,076 ms
280,960 KB |
testcase_03 | AC | 667 ms
281,088 KB |
testcase_04 | AC | 1,101 ms
281,088 KB |
testcase_05 | AC | 1,490 ms
281,088 KB |
testcase_06 | AC | 1,484 ms
281,088 KB |
testcase_07 | AC | 1,264 ms
280,960 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
ソースコード
#include <stdio.h> long long mod_num = 998244353LL; long long root = 3LL; int length = 998244352; long long inverse_root = 0LL; long long inverse_l = 0LL; int log_l = 0; long long pow_root[16] = {}; long long pow_root_inv[16] = {}; long long power_mod (long long a, long long b, long long p) { long long ans = 0LL; a %= p; if (b <= 0LL) { return 1LL; } ans = power_mod(a, b/2LL, p); ans = (ans * ans) % p; if (b%2LL == 1LL) { ans = (ans * a) % p; } return ans; } void setup_ntt (int l) { int tmp_length = 4; log_l = 1; while(tmp_length < 2*l) { tmp_length *= 4; log_l++; } root = power_mod(root, length / tmp_length, mod_num); inverse_root = power_mod(root, mod_num-2LL, mod_num); inverse_l = power_mod((long long) tmp_length, mod_num-2LL, mod_num); length = tmp_length; pow_root[log_l-1] = root; for (int i = log_l-1; i > 0; i--) { pow_root[i-1] = pow_root[i]; pow_root[i-1] *= pow_root[i]; pow_root[i-1] %= mod_num; pow_root[i-1] *= pow_root[i-1]; pow_root[i-1] %= mod_num; } pow_root_inv[log_l-1] = inverse_root; for (int i = log_l-1; i > 0; i--) { pow_root_inv[i-1] = pow_root_inv[i]; pow_root_inv[i-1] *= pow_root_inv[i]; pow_root_inv[i-1] %= mod_num; pow_root_inv[i-1] *= pow_root_inv[i-1]; pow_root_inv[i-1] %= mod_num; } return; } void ntt_4n (long long *a, long long *pow_root) { long long root_1_4 = pow_root[0]; for (int i = 0; i < length; i++) { int idx = 0; int tmp = i; for (int j = 0; j < log_l; j++) { idx <<= 2; idx |= (tmp&3); tmp >>= 2; } if (i < idx) { long long swap = a[i]; a[i] = a[idx]; a[idx] = swap; } } for (int i = 0; i < log_l; i++) { int step = (1<<(2*i)); int stepx4 = (step<<2); int cnt = length/stepx4; long long tmp_root = 1LL; for (int j = 0; j < step; j++) { long long w1 = tmp_root; long long w2 = (w1*w1)%mod_num; long long w3 = (w2*w1)%mod_num; for (int k = 0; k < cnt; k++) { int idx1 = ((k*stepx4)|j); int idx2 = (idx1|step); int idx3 = (idx1|(2*step)); int idx4 = (idx2|idx3); long long a1 = a[idx1]; long long a2 = (a[idx2]*w1)%mod_num; long long a3 = (a[idx3]*w2)%mod_num; long long a4 = (a[idx4]*w3)%mod_num; long long wa2 = (a2*root_1_4)%mod_num; long long wa4 = (a4*root_1_4)%mod_num; long long pad = (mod_num<<1LL); a[idx1] = (a1+a2+a3+a4) % mod_num; a[idx2] = (a1+wa2-a3-wa4+pad) % mod_num; a[idx3] = (a1-a2+a3-a4+pad) % mod_num; a[idx4] = (a1-wa2-a3+wa4+pad) % mod_num; } tmp_root = (tmp_root*pow_root[i])%mod_num; } } return; } int main () { int n = 0; int m = 0; int a[200000] = {}; int b[200000] = {}; int res = 0; long long ans[4000000] = {}; long long work[4000000] = {}; long long mod_num = 998244353LL; long long comb[301][301] = {}; long long cnt[301][301][301] = {}; long long prod[300][601] = {}; res = scanf("%d", &n); res = scanf("%d", &m); for (int i = 0; i < n; i++) { res = scanf("%d", a+i); } for (int i = 0; i < n; i++) { res = scanf("%d", b+i); } for (int i = 0; i <= 300; i++) { comb[i][0] = 1LL; comb[i][i] = 1LL; for (int j = 1; j < i; j++) { comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%mod_num; } } for (int i = 1; i <= 300; i++) { for (int j = 0; j <= 300; j++) { cnt[i][0][j] = comb[i][j]; } for (int j = 1; j <= 300; j++) { for (int k = 0; k < 300; k++) { cnt[i][j][k] = (cnt[i][j-1][k]+cnt[i][j-1][k+1])%mod_num; } if (i >= 300) { cnt[i][j][300] = 1LL; } } } for (int i = 0; i < m; i++) { for (int j = 0; j <= 600; j++) { prod[i][j] = 1LL; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= 300; j++) { prod[i%m][j+300] *= cnt[a[i]][b[i]][j]; prod[i%m][j+300] %= mod_num; } for (int j = 1; j <= 300; j++) { prod[i%m][300-j] *= cnt[b[i]][a[i]][j]; prod[i%m][300-j] %= mod_num; } } setup_ntt(90001); ans[45000] = 1LL; for (int i = 0; i < m; i++) { for (int j = 0; j < length; j++) { work[j] = 0LL; } for (int j = -300; j <= 300; j++) { work[45000+j] = prod[i][300+j]; } ntt_4n(ans, pow_root); ntt_4n(work, pow_root); for (int j = 0; j < length; j++) { ans[j] *= work[j]; ans[j] %= mod_num; } ntt_4n(ans, pow_root_inv); for (int j = 0; j < length; j++) { ans[j] *= inverse_l; ans[j] %= mod_num; } for (int j = 0; j <= 90000; j++) { ans[j] = ans[j+45000]; } for (int j = 90001; j < length; j++) { ans[j] = 0LL; } } printf("%lld\n", ans[45000]); return 0; }