提出 #61661072


ソースコード 拡げる

import sys

input = sys.stdin.readline


def calc(a, b, x, y):
    """
    0 : Takahashi Win
    1 : Aoki Win
    2 : Sente Win
    3 : Gote Win
    """
    if x % 2 == 0 and y % 2 == 0:
        return 2 if (a + b) % 2 == 1 else 3
    if x % 2 == 1 and y % 2 == 1:
        return 2 if b % 2 == 1 else 3
    if x % 2 == 0 and y % 2 == 1:
        if a == 0:
            return 2 if b % 2 == 1 else 3
        if a == 1:
            return 2 if b % 2 == 1 else 0
        return 0
    if x % 2 == 1 and y % 2 == 0:
        if a == 0:
            return 2 if b % 2 == 1 else 3
        if a == 1:
            return 2 if b % 2 == 1 else 1
        return 1


n, x, y = map(int, input().split())
c = [0] * 4
for i in range(n):
    a, b = map(int, input().split())
    c[calc(a, b, x, y)] += 1
mod = 998244353
fact = [1] * (n + 1)
finv = [1] * (n + 1)
for i in range(1, n + 1):
    fact[i] = i * fact[i - 1] % mod
finv[n] = pow(fact[n], mod - 2, mod)
for i in range(n, 0, -1):
    finv[i - 1] = i * finv[i] % mod


def comb(n, k):
    return finv[k] * finv[n - k] % mod * fact[n] % mod


f = [comb(c[0] + c[1], i) for i in range(c[0] + c[1] + 1)]
for i in range(len(f) - 2, -1, -1):
    f[i] += f[i + 1]
    f[i] %= mod
ans = 0
for i in range(c[2] + 1):
    idx = max(0, c[1] + c[2] + 1 - 2 * i)
    if idx < len(f):
        ans += comb(c[2], i) * f[idx]
        ans %= mod
ans *= pow(2, c[3], mod)
print(ans % mod)

提出情報

提出日時
問題 E - Unfair Game
ユーザ sounansya
言語 Python (PyPy 3.10-v7.3.12)
得点 800
コード長 1465 Byte
結果 AC
実行時間 109 ms
メモリ 87492 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 800 / 800
結果
AC × 4
AC × 57
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 02_X0Y0_00.txt, 02_X0Y0_01.txt, 02_X0Y0_02.txt, 02_X0Y0_03.txt, 02_X0Y0_04.txt, 02_X0Y0_05.txt, 02_X0Y0_06.txt, 02_X0Y0_07.txt, 02_X0Y0_08.txt, 02_X0Y0_09.txt, 02_X0Y0_10.txt, 02_X0Y0_11.txt, 03_X1Y1_00.txt, 03_X1Y1_01.txt, 03_X1Y1_02.txt, 03_X1Y1_03.txt, 03_X1Y1_04.txt, 03_X1Y1_05.txt, 03_X1Y1_06.txt, 03_X1Y1_07.txt, 03_X1Y1_08.txt, 03_X1Y1_09.txt, 03_X1Y1_10.txt, 03_X1Y1_11.txt, 04_X0Y1_00.txt, 04_X0Y1_01.txt, 04_X0Y1_02.txt, 04_X0Y1_03.txt, 04_X0Y1_04.txt, 04_X0Y1_05.txt, 04_X0Y1_06.txt, 04_X0Y1_07.txt, 04_X0Y1_08.txt, 04_X0Y1_09.txt, 04_X0Y1_10.txt, 04_X0Y1_11.txt, 04_X0Y1_12.txt, 05_X1Y0_00.txt, 05_X1Y0_01.txt, 05_X1Y0_02.txt, 05_X1Y0_03.txt, 05_X1Y0_04.txt, 05_X1Y0_05.txt, 05_X1Y0_06.txt, 05_X1Y0_07.txt, 05_X1Y0_08.txt, 05_X1Y0_09.txt, 05_X1Y0_10.txt, 05_X1Y0_11.txt, 05_X1Y0_12.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 54 ms 76536 KiB
00_sample_01.txt AC 54 ms 76244 KiB
00_sample_02.txt AC 53 ms 76572 KiB
00_sample_03.txt AC 54 ms 76684 KiB
01_handmade_00.txt AC 54 ms 76372 KiB
01_handmade_01.txt AC 54 ms 76244 KiB
01_handmade_02.txt AC 91 ms 85544 KiB
02_X0Y0_00.txt AC 87 ms 84920 KiB
02_X0Y0_01.txt AC 74 ms 82848 KiB
02_X0Y0_02.txt AC 56 ms 76264 KiB
02_X0Y0_03.txt AC 97 ms 86056 KiB
02_X0Y0_04.txt AC 91 ms 85072 KiB
02_X0Y0_05.txt AC 88 ms 84968 KiB
02_X0Y0_06.txt AC 96 ms 85980 KiB
02_X0Y0_07.txt AC 71 ms 81920 KiB
02_X0Y0_08.txt AC 97 ms 85868 KiB
02_X0Y0_09.txt AC 91 ms 85548 KiB
02_X0Y0_10.txt AC 93 ms 85588 KiB
02_X0Y0_11.txt AC 90 ms 85300 KiB
03_X1Y1_00.txt AC 98 ms 85960 KiB
03_X1Y1_01.txt AC 97 ms 85804 KiB
03_X1Y1_02.txt AC 99 ms 86112 KiB
03_X1Y1_03.txt AC 78 ms 83488 KiB
03_X1Y1_04.txt AC 98 ms 85952 KiB
03_X1Y1_05.txt AC 95 ms 85976 KiB
03_X1Y1_06.txt AC 96 ms 86076 KiB
03_X1Y1_07.txt AC 79 ms 83900 KiB
03_X1Y1_08.txt AC 96 ms 85820 KiB
03_X1Y1_09.txt AC 76 ms 83804 KiB
03_X1Y1_10.txt AC 96 ms 85992 KiB
03_X1Y1_11.txt AC 97 ms 85824 KiB
04_X0Y1_00.txt AC 97 ms 87492 KiB
04_X0Y1_01.txt AC 96 ms 87356 KiB
04_X0Y1_02.txt AC 96 ms 87424 KiB
04_X0Y1_03.txt AC 96 ms 87232 KiB
04_X0Y1_04.txt AC 97 ms 87232 KiB
04_X0Y1_05.txt AC 108 ms 86968 KiB
04_X0Y1_06.txt AC 109 ms 87128 KiB
04_X0Y1_07.txt AC 83 ms 83724 KiB
04_X0Y1_08.txt AC 100 ms 85844 KiB
04_X0Y1_09.txt AC 97 ms 85392 KiB
04_X0Y1_10.txt AC 76 ms 83540 KiB
04_X0Y1_11.txt AC 68 ms 82888 KiB
04_X0Y1_12.txt AC 99 ms 86396 KiB
05_X1Y0_00.txt AC 84 ms 85376 KiB
05_X1Y0_01.txt AC 97 ms 87160 KiB
05_X1Y0_02.txt AC 96 ms 87152 KiB
05_X1Y0_03.txt AC 87 ms 85912 KiB
05_X1Y0_04.txt AC 94 ms 86996 KiB
05_X1Y0_05.txt AC 108 ms 86928 KiB
05_X1Y0_06.txt AC 109 ms 86656 KiB
05_X1Y0_07.txt AC 107 ms 86636 KiB
05_X1Y0_08.txt AC 106 ms 86380 KiB
05_X1Y0_09.txt AC 107 ms 86636 KiB
05_X1Y0_10.txt AC 88 ms 85008 KiB
05_X1Y0_11.txt AC 71 ms 83240 KiB
05_X1Y0_12.txt AC 90 ms 85248 KiB