結果
問題 | No.2133 Take it easy! |
ユーザー | chro_96 |
提出日時 | 2022-11-28 20:00:31 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 2,580 bytes |
コンパイル時間 | 1,017 ms |
コンパイル使用メモリ | 31,488 KB |
実行使用メモリ | 7,768 KB |
最終ジャッジ日時 | 2024-10-05 20:04:01 |
合計ジャッジ時間 | 1,834 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,400 KB |
testcase_01 | AC | 4 ms
6,400 KB |
testcase_02 | AC | 4 ms
6,656 KB |
testcase_03 | AC | 13 ms
7,040 KB |
testcase_04 | AC | 12 ms
7,104 KB |
testcase_05 | AC | 4 ms
6,528 KB |
testcase_06 | AC | 4 ms
6,528 KB |
testcase_07 | AC | 13 ms
7,624 KB |
testcase_08 | AC | 15 ms
7,552 KB |
testcase_09 | AC | 16 ms
7,680 KB |
testcase_10 | AC | 15 ms
7,740 KB |
testcase_11 | AC | 12 ms
7,296 KB |
testcase_12 | AC | 12 ms
7,040 KB |
testcase_13 | AC | 14 ms
7,296 KB |
testcase_14 | AC | 15 ms
7,424 KB |
testcase_15 | AC | 13 ms
7,288 KB |
testcase_16 | AC | 9 ms
7,040 KB |
testcase_17 | AC | 10 ms
7,000 KB |
testcase_18 | AC | 14 ms
7,768 KB |
testcase_19 | AC | 11 ms
7,484 KB |
testcase_20 | AC | 12 ms
7,040 KB |
testcase_21 | AC | 14 ms
7,252 KB |
testcase_22 | AC | 11 ms
7,040 KB |
testcase_23 | AC | 14 ms
7,464 KB |
testcase_24 | AC | 14 ms
7,168 KB |
testcase_25 | AC | 15 ms
7,732 KB |
testcase_26 | AC | 4 ms
6,528 KB |
testcase_27 | AC | 3 ms
6,528 KB |
testcase_28 | AC | 13 ms
7,168 KB |
ソースコード
#include <stdio.h> #include <stdlib.h> int cmp_ll (const void *ap, const void *bp) { long long a = *(long long *)ap; long long b = *(long long *)bp; if (a < b) { return -1; } if (a > b) { 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; } } return ans; } int main () { int n = 0; int q = 0; int l = 0; int r = 0; int res = 0; long long ans = 1LL; long long mod_num = 998244353LL; long long s[200001] = {}; int cnt = 0; int is_ok = 1; long long fact[200002] = {}; long long invf[200002] = {}; res = scanf("%d", &n); res = scanf("%d", &q); for (int i = 0; i < q; i++) { res = scanf("%d", &l); res = scanf("%d", &r); s[l-1] |= (1LL<<((long long)i)); s[r] |= (1LL<<((long long)i)); } fact[0] = 1LL; for (int i = 0; i <= n; i++) { fact[i+1] = fact[i]; fact[i+1] *= (long long) (i+1); fact[i+1] %= mod_num; } invf[n+1] = power_mod(fact[n+1], mod_num-2LL, mod_num); for (int i = n+1; i > 0; i--) { invf[i-1] = invf[i]; invf[i-1] *= (long long) i; invf[i-1] %= mod_num; } for (int i = 1; i < n; i++) { s[i] = (s[i]^s[i-1]); } qsort(s, n, sizeof(long long), cmp_ll); cnt = 1; s[n] = -1LL; for (int i = 1; i <= n; i++) { if (s[i] != s[i-1]) { if (s[i-1] != 0LL && cnt%2 == 1) { is_ok = 0; } else if (cnt%2 == 1) { long long tmp1 = fact[cnt+1]; long long tmp2 = fact[cnt+1]; tmp1 *= invf[(cnt+1)/2]; tmp1 %= mod_num; tmp1 *= invf[(cnt+1)/2]; tmp1 %= mod_num; tmp2 *= invf[(cnt+3)/2]; tmp2 %= mod_num; tmp2 *= invf[(cnt-1)/2]; tmp2 %= mod_num; ans *= tmp1+mod_num-tmp2; ans %= mod_num; } else { long long tmp1 = fact[cnt]; long long tmp2 = fact[cnt]; tmp1 *= invf[cnt/2]; tmp1 %= mod_num; tmp1 *= invf[cnt/2]; tmp1 %= mod_num; tmp2 *= invf[1+cnt/2]; tmp2 %= mod_num; tmp2 *= invf[cnt/2-1]; tmp2 %= mod_num; ans *= tmp1+mod_num-tmp2; ans %= mod_num; } cnt = 0; } cnt++; } if (is_ok <= 0) { printf("0\n"); return 0; } ans *= fact[n/2]; ans %= mod_num; ans *= fact[n-n/2]; ans %= mod_num; printf("%lld\n", ans); return 0; }