提出 #17355625


ソースコード 拡げる

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

@njit((i8, i8[:]), cache=True)
def main(N, AB):
    pow2 = np.ones(1 << 15, np.int64)
    for n in range(1, 1 << 15):
        pow2[n] = pow2[n - 1] + pow2[n - 1]
        if pow2[n] >= MOD:
            pow2[n] -= MOD
    A, B = AB[::2] - 1, AB[1::2] - 1
    G = np.zeros((N, N), np.int64)
    for i in range(len(A)):
        a, b = A[i], B[i]
        G[a, b] = G[b, a] = 1
    dp0 = np.zeros((1 << N), np.int64)  # 集合に対して、その中におさまっている辺の数
    for s in range(1 << N):
        for v in range(N):
            if not s & 1 << v:
                continue
            for w in range(v + 1, N):
                if not s & 1 << w:
                    continue
                dp0[s] += G[v, w]
    dp1 = np.zeros(1 << N, np.int64)  # S をラベル付き二部グラフにする方法
    dp1[0] = 1
    for s in range(1 << N):
        t = s
        while True:
            u = s ^ t
            # (u,t) 辺を数える
            e = 0
            for v in range(N):
                """(t, u) 辺の個数を数える
                if u & 1 << v:
                    e += dp0[t, v]"""
                e = dp0[u + t] - dp0[u] - dp0[t]
            dp1[s] += pow2[e]
            if t == 0:
                break
            t = (t - 1) & s
        dp1[s] %= MOD
    dp2 = np.zeros(1 << N, np.int64)  # S をラベル付き連結二部グラフにする方法
    for s in range(1, 1 << N):
        for v0 in range(N):
            if s & 1 << v0:
                break
        # v0 を含む連結成分が t
        x = dp1[s]
        t = s
        while t:
            t = (t - 1) & s
            if t & 1 << v0:
                u = s ^ t
                x -= dp2[t] * dp1[u] % MOD
        dp2[s] = x % MOD
    ans = dp2[-1]
    if ans & 1:
        ans += MOD
    return ans >> 1

N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64)

print(main(N, AB))

提出情報

提出日時
問題 F - Lights Out on Connected Graph
ユーザ maspy
言語 Python (3.8.2)
得点 900
コード長 2189 Byte
結果 AC
実行時間 1086 ms
メモリ 108288 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 900 / 900
結果
AC × 3
AC × 33
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 1086 ms 108240 KiB
random_02.txt AC 1077 ms 107520 KiB
random_03.txt AC 1080 ms 108208 KiB
random_04.txt AC 1079 ms 107000 KiB
random_05.txt AC 1081 ms 108248 KiB
random_06.txt AC 1071 ms 107152 KiB
random_07.txt AC 1078 ms 108252 KiB
random_08.txt AC 1073 ms 108288 KiB
random_09.txt AC 1078 ms 107216 KiB
random_10.txt AC 1076 ms 108212 KiB
random_11.txt AC 473 ms 105832 KiB
random_12.txt AC 464 ms 105592 KiB
random_13.txt AC 456 ms 106376 KiB
random_14.txt AC 451 ms 105492 KiB
random_15.txt AC 451 ms 105800 KiB
random_16.txt AC 458 ms 106392 KiB
random_17.txt AC 453 ms 105596 KiB
random_18.txt AC 456 ms 106312 KiB
random_19.txt AC 452 ms 106396 KiB
random_20.txt AC 453 ms 105832 KiB
random_21.txt AC 481 ms 106536 KiB
random_22.txt AC 455 ms 105832 KiB
random_23.txt AC 453 ms 106408 KiB
random_24.txt AC 455 ms 106324 KiB
random_25.txt AC 633 ms 106676 KiB
random_26.txt AC 453 ms 105820 KiB
random_27.txt AC 454 ms 105848 KiB
random_28.txt AC 451 ms 106332 KiB
random_29.txt AC 1061 ms 108196 KiB
random_30.txt AC 472 ms 106284 KiB
sample_01.txt AC 465 ms 105672 KiB
sample_02.txt AC 464 ms 105592 KiB
sample_03.txt AC 1062 ms 107776 KiB