結果
問題 | No.2907 Business Revealing Dora Tiles |
ユーザー | 👑 獅子座じゃない人 |
提出日時 | 2024-06-06 14:58:52 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,833 bytes |
コンパイル時間 | 5,744 ms |
コンパイル使用メモリ | 81,772 KB |
実行使用メモリ | 100,740 KB |
最終ジャッジ日時 | 2024-09-23 12:04:40 |
合計ジャッジ時間 | 75,466 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 125 ms
77,188 KB |
testcase_01 | AC | 75 ms
77,168 KB |
testcase_02 | AC | 76 ms
77,192 KB |
testcase_03 | AC | 96 ms
77,396 KB |
testcase_04 | AC | 99 ms
77,664 KB |
testcase_05 | AC | 117 ms
77,424 KB |
testcase_06 | AC | 172 ms
80,052 KB |
testcase_07 | AC | 80 ms
77,212 KB |
testcase_08 | AC | 96 ms
77,172 KB |
testcase_09 | AC | 96 ms
77,540 KB |
testcase_10 | AC | 80 ms
77,164 KB |
testcase_11 | AC | 1,934 ms
90,728 KB |
testcase_12 | AC | 92 ms
77,504 KB |
testcase_13 | AC | 106 ms
78,172 KB |
testcase_14 | AC | 98 ms
77,152 KB |
testcase_15 | AC | 184 ms
79,460 KB |
testcase_16 | AC | 76 ms
77,072 KB |
testcase_17 | AC | 92 ms
77,392 KB |
testcase_18 | AC | 634 ms
83,400 KB |
testcase_19 | AC | 99 ms
77,276 KB |
testcase_20 | AC | 81 ms
77,340 KB |
testcase_21 | AC | 1,512 ms
85,576 KB |
testcase_22 | AC | 224 ms
79,704 KB |
testcase_23 | AC | 463 ms
81,484 KB |
testcase_24 | AC | 2,390 ms
95,060 KB |
testcase_25 | AC | 2,323 ms
94,044 KB |
testcase_26 | AC | 2,451 ms
93,908 KB |
testcase_27 | AC | 2,425 ms
95,184 KB |
testcase_28 | AC | 2,295 ms
92,632 KB |
testcase_29 | AC | 2,372 ms
94,560 KB |
testcase_30 | AC | 2,352 ms
93,544 KB |
testcase_31 | AC | 2,329 ms
94,424 KB |
testcase_32 | AC | 2,429 ms
95,972 KB |
testcase_33 | AC | 2,275 ms
93,264 KB |
testcase_34 | AC | 2,365 ms
95,320 KB |
testcase_35 | AC | 2,323 ms
94,804 KB |
testcase_36 | AC | 2,333 ms
97,364 KB |
testcase_37 | AC | 2,333 ms
93,508 KB |
testcase_38 | AC | 2,348 ms
93,656 KB |
testcase_39 | AC | 2,410 ms
94,272 KB |
testcase_40 | AC | 2,386 ms
95,700 KB |
testcase_41 | AC | 2,327 ms
93,540 KB |
testcase_42 | AC | 2,431 ms
97,640 KB |
testcase_43 | AC | 2,435 ms
95,340 KB |
testcase_44 | TLE | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
ソースコード
from itertools import combinations nim_prod_table=[[0]*256 for _ in range(256)] nim_inv_table=[0]*65536 def nim_prod_precalc(): nim_prod_table[0][0]=0 nim_prod_table[0][1]=0 nim_prod_table[1][0]=0 nim_prod_table[1][1]=1 nim_inv_table[1]=1 for d in range(3): p=1<<d for a in range(1<<(2*p)): for b in range(1<<p, 1<<(2*p)): a_h=a>>p a_l=a-(a_h<<p) b_h=b>>p b_l=b-(b_h<<p) al_bl=nim_prod_table[a_l][b_l] ahl_bhl=nim_prod_table[a_h^a_l][b_h^b_l] ah_bh=nim_prod_table[a_h][b_h] ah_bh_h=nim_prod_table[ah_bh][1<<(p-1)] nim_prod_table[a][b]=nim_prod_table[b][a]=((al_bl^ahl_bhl)<<p)^(al_bl^ah_bh_h) if nim_prod_table[a][b]==1: nim_inv_table[a]=b nim_inv_table[b]=a def nim_product_power(a: int, n: int, p: int=64) -> int: if p==64: if a<(1<<8) and n<8: p=8 elif a<(1<<16) and n<16: p=16 elif a<(1<<32) and n<32: p=32 if p==8: return nim_prod_table[a][1<<n] p//=2 a_h=a>>p a_l=a-(a_h<<p) if n<p: return (nim_product_power(a_h, n, p)<<p)^nim_product_power(a_l, n, p) else: n-=p return (nim_product_power(a_h^a_l, n, p)<<p)^nim_product_power(nim_product_power(a_h, n, p), p-1, p) def nim_square(a: int, p: int=64) -> int: if p==64: if a<(1<<8): p=8 elif a<(1<<16): p=16 elif a<(1<<32): p=32 if p==8: return nim_prod_table[a][a] p//=2 a_h=a>>p a_l=a-(a_h << p) h_sq=nim_square(a_h, p) l_sq=nim_square(a_l, p) return (h_sq<<p)^nim_product_power(h_sq, p-1, p)^l_sq def nim_product(a: int, b: int, p: int=64) -> int: if a==0 or b==0: return 0 if a==1: return b if b==1: return a if p==64: if a<(1<<8) and b<(1<<8): p=8 elif a<(1<<16) and b<(1<<16): p=16 elif a<(1<<32) and b<(1<<32): p=32 if p==8: return nim_prod_table[a][b] p//=2 a_h=a>>p a_l=a-(a_h<<p) b_h=b>>p b_l=b-(b_h<<p) al_bl=nim_product(a_l, b_l, p) ahl_bhl=nim_product(a_h^a_l, b_h^b_l, p) ah_bh=nim_product(a_h, b_h, p) ah_bh_h=nim_product_power(ah_bh, p-1, p) return ((al_bl^ahl_bhl)<<p)^(al_bl^ah_bh_h) def nim_inv_precalc(): for a in range(1<<8, 1<<16): p=8 a_h=a>>p a_l=a-(a_h<<p) half_inv=nim_inv_table[nim_product(a_h^a_l, a_l, p)^nim_product_power(nim_square(a_h, p), p-1, p)] nim_inv_table[a]=(nim_product(half_inv, a_h, p)<<p)^nim_product(half_inv, a_h^a_l, p) def nim_inv(a: int, p: int=64) -> int: if p==64: if a<(1<<16): p=16 elif a<(1<<32): p=32 if p==16: return nim_inv_table[a] p//=2 a_h=a>>p a_l=a-(a_h<<p) half_inv=nim_inv(nim_product(a_h^a_l, a_l, p)^nim_product_power(nim_square(a_h, p), p-1, p), p) return (nim_product(half_inv, a_h, p)<<p)^nim_product(half_inv, a_h^a_l, p) def gauss(r: int, c: int, m: list[list[int]], exists: list[int]) -> int: rank=0 for i in range(c): if not exists[i]: continue pivot=-1 for j in range(rank, r): if m[j][i]>0: pivot=j break if pivot==-1: continue m[pivot], m[rank]=m[rank], m[pivot] if rank==r-1: rank+=1 break inv=nim_inv(m[rank][i]) m[rank][i]=1 for k in range(0, c): if k==i: continue m[rank][k]=nim_product(m[rank][k], inv) for j in range(r): if j==rank: continue factor=m[j][i] m[j][i]=0 for k in range(0, c): if k==i: continue m[j][k]^=nim_product(m[rank][k], factor) rank+=1 return rank nim_prod_precalc() nim_inv_precalc() n,t=map(int, input().split()) h=[list(map(lambda a: int(a)-1, input().split())) for _ in range(t)] rank=gauss(t, n, h, [1]*n) ranks=[0]*(1<<n) for members_tuple in combinations(range(n), rank): members=list(members_tuple) is_member=[0]*n s=0 for i in members: is_member[i]=1 s+=1<<i if gauss(rank, n, h, is_member)==rank: ranks[s]=rank for r in reversed(range(rank)): for members_tuple in combinations(range(n), r): members=list(members_tuple) is_member=[0]*n s=0 for i in members: is_member[i]=1 s+=1<<i for i in range(n): if is_member[i]: continue if ranks[s+(1<<i)]>0: ranks[s]=r break for r in range(n): for members_tuple in combinations(range(n), r): members=list(members_tuple) is_member=[0]*n s=0 for i in members: is_member[i]=1 s+=1<<i for i in range(n): if is_member[i]: continue ranks[s+(1<<i)]=max(ranks[s], ranks[s+(1<<i)]) ans=0 mods=[1, 932051910, 299560064, 268998206, 169907034, 617122664, 934978948, 751815647, 60241440, 910883406, 623687709, 299771973, 824242875, 286857587, 12424206, 89078497, 595200811, 971438438, 608817788, 778210505, 170380535] MOD=998244353 for s in range(1<<n): count=s.bit_count() if n%2>0: if count%2>0: ans+=mods[count-ranks[s]] else: ans-=mods[count-ranks[s]] else: if count%2>0: ans-=mods[count-ranks[s]] else: ans+=mods[count-ranks[s]] ans%=MOD print(ans)