結果
問題 | No.2907 Business Revealing Dora Tiles |
ユーザー | 👑 Nachia |
提出日時 | 2024-09-18 23:17:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,800 ms / 3,000 ms |
コード長 | 4,822 bytes |
コンパイル時間 | 5,142 ms |
コンパイル使用メモリ | 81,956 KB |
実行使用メモリ | 97,780 KB |
最終ジャッジ日時 | 2024-09-23 13:30:04 |
合計ジャッジ時間 | 50,186 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 65 ms
65,724 KB |
testcase_01 | AC | 50 ms
65,196 KB |
testcase_02 | AC | 49 ms
64,616 KB |
testcase_03 | AC | 74 ms
76,556 KB |
testcase_04 | AC | 89 ms
77,168 KB |
testcase_05 | AC | 85 ms
77,040 KB |
testcase_06 | AC | 134 ms
78,144 KB |
testcase_07 | AC | 53 ms
63,900 KB |
testcase_08 | AC | 61 ms
71,144 KB |
testcase_09 | AC | 97 ms
76,988 KB |
testcase_10 | AC | 67 ms
73,920 KB |
testcase_11 | AC | 532 ms
81,944 KB |
testcase_12 | AC | 74 ms
76,488 KB |
testcase_13 | AC | 85 ms
76,884 KB |
testcase_14 | AC | 93 ms
76,904 KB |
testcase_15 | AC | 92 ms
77,204 KB |
testcase_16 | AC | 52 ms
67,040 KB |
testcase_17 | AC | 77 ms
76,960 KB |
testcase_18 | AC | 202 ms
78,844 KB |
testcase_19 | AC | 83 ms
76,784 KB |
testcase_20 | AC | 65 ms
74,700 KB |
testcase_21 | AC | 602 ms
82,608 KB |
testcase_22 | AC | 212 ms
79,296 KB |
testcase_23 | AC | 385 ms
83,104 KB |
testcase_24 | AC | 737 ms
86,192 KB |
testcase_25 | AC | 735 ms
85,908 KB |
testcase_26 | AC | 739 ms
85,292 KB |
testcase_27 | AC | 833 ms
85,236 KB |
testcase_28 | AC | 689 ms
85,620 KB |
testcase_29 | AC | 753 ms
85,756 KB |
testcase_30 | AC | 719 ms
85,696 KB |
testcase_31 | AC | 757 ms
85,320 KB |
testcase_32 | AC | 767 ms
85,324 KB |
testcase_33 | AC | 730 ms
85,664 KB |
testcase_34 | AC | 764 ms
86,088 KB |
testcase_35 | AC | 720 ms
85,644 KB |
testcase_36 | AC | 720 ms
85,900 KB |
testcase_37 | AC | 687 ms
86,092 KB |
testcase_38 | AC | 703 ms
86,052 KB |
testcase_39 | AC | 728 ms
85,588 KB |
testcase_40 | AC | 689 ms
85,688 KB |
testcase_41 | AC | 769 ms
85,680 KB |
testcase_42 | AC | 712 ms
85,320 KB |
testcase_43 | AC | 788 ms
85,692 KB |
testcase_44 | AC | 1,869 ms
92,980 KB |
testcase_45 | AC | 2,499 ms
97,780 KB |
testcase_46 | AC | 1,576 ms
93,504 KB |
testcase_47 | AC | 964 ms
87,168 KB |
testcase_48 | AC | 1,014 ms
89,672 KB |
testcase_49 | AC | 2,800 ms
95,900 KB |
testcase_50 | AC | 2,141 ms
92,344 KB |
testcase_51 | AC | 310 ms
79,524 KB |
testcase_52 | AC | 749 ms
85,404 KB |
testcase_53 | AC | 895 ms
86,984 KB |
testcase_54 | AC | 397 ms
82,864 KB |
testcase_55 | AC | 899 ms
87,072 KB |
testcase_56 | AC | 922 ms
86,672 KB |
testcase_57 | AC | 949 ms
86,732 KB |
testcase_58 | AC | 960 ms
86,520 KB |
testcase_59 | AC | 884 ms
87,612 KB |
ソースコード
''' translated https://yukicoder.me/submissions/1011436 ''' nim_precalc1 = [] nim_inv_precalc1 = [] def nim_fill_precalc1() : global nim_precalc1 nim_precalc1 = [0] * (2 ** 16) nim_precalc1[(1 << 8) ^ 1] = 1 dd = 1 while dd < 8 : d = 1 << dd c = d >> 1 for a0 in range(d) : for a1 in range(d) : if (a0 | a1) != 0 : for b0 in range(d) : for b1 in range(d) : if (b0 | b1) != 0 : buf = 0 buf ^= nim_precalc1[(a1 << 8) ^ b1] buf ^= nim_precalc1[(a1 << 8) ^ b0] buf ^= nim_precalc1[(a0 << 8) ^ b1] buf <<= dd buf ^= nim_precalc1[(c << 8) ^ nim_precalc1[(a1 << 8) ^ b1]] buf ^= nim_precalc1[(a0 << 8) ^ b0] nim_precalc1[(((a1 << dd) ^ a0) << 8) ^ ((b1 << dd) ^ b0)] = buf dd *= 2 def nim_inv_precalc() : global nim_inv_precalc1 nim_inv_precalc1 = [0] * 256 for i in range(256) : for j in range(256) : if nim_precalc1[(i << 8) ^ j] == 1 : nim_inv_precalc1[i] = j break def nim_product_full(a, b, d = 6) : if a == 0 or b == 0 : return 0 if d == 3 : return nim_precalc1[(a << 8) ^ b] d -= 1 lm = (1 << (1 << d)) - 1 us = (1 << d) buf = 0 a1b1 = nim_product_full(a >> us, b >> us, d) a2b2 = nim_product_full(a & lm, b & lm, d) aabb = nim_product_full((a & lm) ^ (a >> us), (b & lm) ^ (b >> us), d) buf ^= (aabb ^ a2b2) buf <<= us buf ^= a2b2 buf ^= nim_product_full(1 << (us - 1), a1b1, d) return buf def nim_inv_full(a, d = 6) : if a < 256 : return nim_inv_precalc1[a] p = 1 << (d - 1) a_h = a >> p a_l = a - (a_h << p) half_inv = nim_inv_full(nim_product_full(a_h ^ a_l, a_l, d-1) ^ nim_product_full(nim_product_full(a_h, a_h, d-1), 1 << (p-1)), d-1) return (nim_product_full(half_inv, a_h, d-1) << p) ^ nim_product_full(half_inv, a_h ^ a_l, d-1) def nim_product(a, b) : return nim_product_full(a, b) def nim_inv(a) : return nim_inv_full(a) nim_fill_precalc1() nim_inv_precalc() def popcount(a) : ans = 0 for i in range(64) : ans += (a >> i) & 1 return ans def testcase() : n, t = map(int,input().split()) a = [list(map(int,input().split())) for _ in range(t)] for i in range(t) : for j in range(n) : a[i][j] -= 1 y = 0 for x in reversed(range(0, n)) : if y < t : for tt in range(y, t) : if a[tt][x] != 0 : a[y], a[tt] = a[tt], a[y] break if a[y][x] == 0 : continue inv_b = nim_inv(a[y][x]) for tt in range(n) : a[y][tt] = nim_product(a[y][tt], inv_b) for yy in range(t) : if y != yy : times = a[yy][x] for j in range(n) : a[yy][j] ^= nim_product(a[y][j], times) y += 1 ranks = [0] * (1 << n) def most_significant(x) : f = len(x) - 1 while f >= 0 and x[f] == 0 : f -= 1 return f def dfs(q, offseti, offsetd, z) : if z == 1 : ranks[offseti] = offsetd if q[0][0] : offsetd += 64 ranks[offseti + 1] = offsetd return q1 = [[i for i in j] for j in q] # deep copy d1 = offsetd if q1[-1][-1] != 0 : d1 += 64 q1.pop() for qq in q1 : qq.pop() dfs(q1, offseti + (1 << (z-1)), d1, z-1) q1 = q for qq in q1 : qq.pop() q1x = q1[-1] q1.pop() b = most_significant(q1x) if b >= 0 : inv_b = nim_inv(q1x[b]) for t in range(b+1) : q1x[t] = nim_product(q1x[t], inv_b) for t in range(b+1, len(q1)) : times = q1[t][b] for i in range(b) : q1[t][i] ^= nim_product(q1x[i], times) q1[t][b] = 0 q1[b], q1x = q1x, q1[b] dfs(q1, offseti, offsetd, z-1) qinit = [[0] * n for _ in range(n)] for i in range(y) : qinit[most_significant(a[i])] = a[i] dfs(qinit, 0, 0, n) w = [0] * (1 << n) for i in range(1 << n) : w[i] = pow(2, 64 * popcount(i) - ranks[i], 998244353) ans = 0 for i in range(1 << n) : ans += w[i] * (-1 if (n - popcount(i)) % 2 == 1 else 1) print(ans % 998244353) testcase()