結果
問題 | No.2512 Mountain Sequences |
ユーザー | chro_96 |
提出日時 | 2023-10-20 23:09:41 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1,199 ms / 3,000 ms |
コード長 | 3,006 bytes |
コンパイル時間 | 1,515 ms |
コンパイル使用メモリ | 32,256 KB |
実行使用メモリ | 14,340 KB |
最終ジャッジ日時 | 2024-09-20 22:17:17 |
合計ジャッジ時間 | 18,237 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
12,076 KB |
testcase_01 | AC | 14 ms
11,988 KB |
testcase_02 | AC | 14 ms
11,860 KB |
testcase_03 | AC | 14 ms
11,972 KB |
testcase_04 | AC | 14 ms
11,932 KB |
testcase_05 | AC | 14 ms
11,848 KB |
testcase_06 | AC | 14 ms
12,068 KB |
testcase_07 | AC | 14 ms
12,028 KB |
testcase_08 | AC | 14 ms
11,872 KB |
testcase_09 | AC | 14 ms
12,064 KB |
testcase_10 | AC | 1,189 ms
14,172 KB |
testcase_11 | AC | 1,193 ms
14,100 KB |
testcase_12 | AC | 1,193 ms
14,128 KB |
testcase_13 | AC | 1,199 ms
14,136 KB |
testcase_14 | AC | 1,190 ms
14,072 KB |
testcase_15 | AC | 1,190 ms
14,048 KB |
testcase_16 | AC | 1,185 ms
14,112 KB |
testcase_17 | AC | 1,187 ms
14,108 KB |
testcase_18 | AC | 1,190 ms
14,140 KB |
testcase_19 | AC | 1,191 ms
14,152 KB |
testcase_20 | AC | 376 ms
14,176 KB |
testcase_21 | AC | 375 ms
14,340 KB |
testcase_22 | AC | 376 ms
14,208 KB |
testcase_23 | AC | 375 ms
14,136 KB |
testcase_24 | AC | 375 ms
14,220 KB |
testcase_25 | AC | 87 ms
12,868 KB |
testcase_26 | AC | 87 ms
13,080 KB |
testcase_27 | AC | 90 ms
12,972 KB |
testcase_28 | AC | 341 ms
14,072 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> #define RANGE_SIZE 450 int cmp_mo (const void *a, const void *b) { int *a_ = (int *)a; int *b_ = (int *)b; if (a_[0]/RANGE_SIZE < b_[0]/RANGE_SIZE) { return -1; } if (a_[0]/RANGE_SIZE > b_[0]/RANGE_SIZE) { return 1; } if (a_[1] < b_[1]) { return -1; } if (a_[1] > b_[1]) { return 1; } return 0; } long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans * (a % mod_num)) % mod_num; } } return ans; } int main () { int t = 0; int nm[200000][3] = {}; int res = 0; long long ans[200000] = {}; long long mod_num = 998244353LL; long long fact[400001] = {}; long long invf[400001] = {}; long long inv2 = (mod_num+1LL)/2LL; res = scanf("%d", &t); for (int i = 0; i < t; i++) { res = scanf("%d", nm[i]); res = scanf("%d", nm[i]+1); nm[i][2] = i; } fact[0] = 1LL; for (int i = 0; i < 400000; i++) { fact[i+1] = fact[i]; fact[i+1] *= (long long)(i+1); fact[i+1] %= mod_num; } invf[400000] = power_mod(fact[400000], mod_num-2LL, mod_num); for (int i = 400000; i > 0; i--) { invf[i-1] = invf[i]; invf[i-1] *= (long long)i; invf[i-1] %= mod_num; } qsort(nm, t, sizeof(int)*3, cmp_mo); for (int i = 0; i < nm[0][1]; i++) { if (2*i >= nm[0][0]-1) { long long tmp = (fact[2*i]*invf[nm[0][0]-1])%mod_num; ans[nm[0][2]] += (tmp*invf[2*i-nm[0][0]+1])%mod_num; } } ans[nm[0][2]] %= mod_num; for (int i = 1; i < t; i++) { int pn = nm[i-1][0]; int pm = nm[i-1][1]; ans[nm[i][2]] = ans[nm[i-1][2]]; while (pn != nm[i][0] || pm != nm[i][1]) { if (pn < nm[i][0]) { long long tmp = 0LL; if (2*pm > pn) { tmp = (fact[2*pm]*invf[pn+1])%mod_num; tmp = (tmp*invf[2*pm-pn-1])%mod_num; } ans[nm[i][2]] = (tmp+mod_num-ans[nm[i][2]])%mod_num; ans[nm[i][2]] *= inv2; ans[nm[i][2]] %= mod_num; pn++; } else if (pn > nm[i][0]) { long long tmp = 0LL; if (2*pm >= pn) { tmp = (fact[2*pm]*invf[pn])%mod_num; tmp = (tmp*invf[2*pm-pn])%mod_num; } ans[nm[i][2]] = (tmp+2LL*mod_num-2LL*ans[nm[i][2]])%mod_num; pn--; } else if (pm < nm[i][1]) { if (2*pm >= pn-1) { long long tmp = (fact[2*pm]*invf[pn-1])%mod_num; ans[nm[i][2]] += tmp*invf[2*pm-pn+1]; ans[nm[i][2]] %= mod_num; } pm++; } else { if (2*pm-2 >= pn-1) { long long tmp = (fact[2*pm-2]*invf[pn-1])%mod_num; ans[nm[i][2]] += mod_num-(tmp*invf[2*pm-pn-1])%mod_num; ans[nm[i][2]] %= mod_num; } pm--; } } } for (int i = 0; i < t; i++) { printf("%lld\n", ans[i]); } return 0; }