結果

問題 No.2907 Business Revealing Dora Tiles
ユーザー 👑 amentorimaruamentorimaru
提出日時 2024-06-01 13:48:26
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 4,466 bytes
コンパイル時間 5,200 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 95,436 KB
最終ジャッジ日時 2024-09-23 10:59:27
合計ジャッジ時間 25,070 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
94,672 KB
testcase_01 AC 209 ms
94,424 KB
testcase_02 AC 206 ms
94,412 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from fractions import Fraction
input = sys.stdin.readline
def read_values(): return tuple(map(int, input().split()))
def read_list(): return list(read_values())

class Nimber():
    def __init__(self, loglog_small_product = 3, loglog_small_inv = 4, loglog_siz = 6):        
        self.loglog_siz = loglog_siz
        self.siz = 1 << (1 << loglog_siz)
        self.loglog_small_product = loglog_small_product
        self.fill_small_product(loglog_small_product)
        self.loglog_small_inv = loglog_small_inv
        self.fill_small_inv(loglog_small_inv)
        
    def fill_small_product(self, loglog_small):
        log_small = 1 << loglog_small
        self.small_product = [[0] * (1 << log_small) for _ in range(1 << log_small)]
        for a in range(1, 1 << log_small):
            self.small_product[a][1] = a
            self.small_product[1][a] = a
            
            d = log_small // 2
            while a < (1 << d):
                d >>= 1
            for b in range(2, a + 1):
                a1, a2 = a >> d, a & ((1 << d) - 1)    
                b1, b2 = b >> d, b & ((1 << d) - 1)    
                ab1 = self.small_product[a1][b1]
                ab2 = self.small_product[a2][b2]
                ab3 = self.small_product[a1 ^ a2][b1 ^ b2]
                res = self.small_product[ab1][1 << (d - 1)] ^ ab2 ^ ((ab2 ^ ab3) << d)
                self.small_product[a][b] = res
                self.small_product[b][a] = res
       
    def fill_small_inv(self, loglog_small):
        log_small = 1 << loglog_small
        self.small_inv = [0, 1, 3, 2]
        lls = 2
        for a in range(4, 1 << log_small):
            if a >= (1 << (1 << lls)):
                lls += 1
            self.small_inv.append(self.inv_impl(a, lls))

    def product_impl(self, a, b, loglog):
        if loglog <= self.loglog_small_product:
            return self.small_product[a][b]
        if max(a,b) <= 1:
            return a * b
        us = 1 << (loglog - 1)
        assert(a < (1 << (1 << loglog)) and b < (1 << (1 << loglog)))
        lm = (1 << us) - 1        
        ab1 = self.product_impl(a >> us, b >> us, loglog - 1)
        ab2 = self.product_impl(a & lm, b & lm, loglog - 1)
        ab3 = self.product_impl((a & lm) ^ (a >> us), (b & lm) ^ (b >> us), loglog - 1)
        res = ab3 ^ ab2
        res <<= us
        res ^= ab2
        res ^= self.product_impl(1 << (us - 1), ab1, loglog - 1)
        return res

    def product(self, a, b):
        assert(0 <= a < self.siz and 0 <= b < self.siz)
        return self.product_impl(a, b, self.loglog_siz)
    
    def inv_impl(self, a, loglog):
        if a < len(self.small_inv):
            return self.small_inv[a] 
        p = 1 << (loglog - 1)
        assert(a < (1<<(1<<loglog)))
        ah = a >> p
        al = a - (ah << p)
        a2 = self.product_impl(ah ^ al, al, loglog)
        ahsq = self.product_impl(ah, ah, loglog - 1)
        a3 = self.product_impl(ahsq, 1 << (p - 1), loglog - 1)
        half = self.inv_impl(a2 ^ a3, loglog - 1)
        return (self.product_impl(half, ah, loglog - 1) << p) ^ (self.product_impl(half, ah ^ al, loglog))
    
    def inv(self, a):
        assert(0 <= a < self.siz)
        for p in range(self.loglog_siz):
            if p < (1 << (1 << p)):
                return self.inv_impl(a, p)
        

def main():  
    nimber = Nimber()
    n,t = read_values()
    h = [read_list() for _ in range(t)]
    for i in range(t):
        for j in range(n):
            h[i][j] -= 1        
    mod = 998244353
    tp = (1 << 64) % mod
    ans = 0
    bn = 1 << n
    for b in range(bn):
        use = 0
        add = 1
        for j in range(n):
            if (b >> j) & 1:
                continue
            idx = -1
            for i in range(t):
                if (use >> i) & 1 == 0 and h[i][j] != 0:
                    idx = i                    
                    inv = nimber.inv(h[i][j])
                    break
            if idx == -1:
                add *= tp
                add %= mod
                continue
            use |= 1 << i
            for i in range(t):
                if i != idx and h[i][j] != 0:
                    mul = nimber.product(inv, h[i][j])
                    for jj in range(n):
                        h[i][jj] ^= nimber.product(mul, h[idx][jj])
        ans += add if int.bit_count(b) % 2 == 0 else -add
        ans %= mod
    print(ans)
        
if __name__ == "__main__":
    main()
0