結果

問題 No.803 Very Limited Xor Subset
ユーザー shotoyooshotoyoo
提出日時 2020-11-22 15:13:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 3,095 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 86,652 KB
実行使用メモリ 79,796 KB
最終ジャッジ日時 2023-09-30 22:52:46
合計ジャッジ時間 8,693 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,488 KB
testcase_01 AC 73 ms
71,460 KB
testcase_02 AC 73 ms
71,244 KB
testcase_03 AC 75 ms
70,968 KB
testcase_04 AC 79 ms
75,072 KB
testcase_05 AC 77 ms
75,280 KB
testcase_06 AC 76 ms
71,316 KB
testcase_07 AC 74 ms
71,276 KB
testcase_08 AC 75 ms
71,496 KB
testcase_09 AC 73 ms
71,480 KB
testcase_10 AC 77 ms
75,204 KB
testcase_11 AC 79 ms
75,624 KB
testcase_12 AC 80 ms
75,420 KB
testcase_13 AC 78 ms
75,696 KB
testcase_14 AC 163 ms
78,764 KB
testcase_15 AC 157 ms
78,732 KB
testcase_16 AC 157 ms
78,752 KB
testcase_17 AC 155 ms
78,460 KB
testcase_18 AC 155 ms
78,868 KB
testcase_19 AC 166 ms
78,820 KB
testcase_20 AC 159 ms
78,980 KB
testcase_21 AC 160 ms
78,972 KB
testcase_22 AC 158 ms
78,792 KB
testcase_23 AC 166 ms
79,028 KB
testcase_24 AC 166 ms
79,436 KB
testcase_25 AC 168 ms
79,204 KB
testcase_26 AC 165 ms
79,208 KB
testcase_27 AC 167 ms
79,444 KB
testcase_28 AC 166 ms
79,080 KB
testcase_29 AC 163 ms
79,080 KB
testcase_30 AC 164 ms
79,180 KB
testcase_31 AC 165 ms
78,880 KB
testcase_32 AC 166 ms
79,444 KB
testcase_33 AC 164 ms
79,512 KB
testcase_34 AC 112 ms
77,744 KB
testcase_35 AC 168 ms
79,496 KB
testcase_36 AC 148 ms
78,412 KB
testcase_37 AC 157 ms
78,668 KB
testcase_38 AC 97 ms
77,272 KB
testcase_39 AC 96 ms
76,608 KB
testcase_40 AC 155 ms
78,980 KB
testcase_41 AC 167 ms
79,796 KB
testcase_42 AC 168 ms
79,748 KB
testcase_43 AC 157 ms
79,424 KB
testcase_44 AC 72 ms
71,256 KB
testcase_45 AC 72 ms
71,440 KB
testcase_46 AC 90 ms
76,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

"""ビット行列
1次方程式、ランクrank
"""
class BitMatrix:
    def __init__(self, h, w, v=None):
        self.h = h
        self.w = w
        self.l = [0]*h
        if v is not None:
            for i in range(h):
                for j in range(w):
                    if v[i][j]:
                        self.l[i] |= (1<<j)
    def to_matrix(self):
        M = []
        for i in range(self.h):
            l = []
            for j in range(self.w):
                l.append(self.l[i]>>j&1)
            M.append(l)
        return M
    def swap(self, i, j):
        """i行目とj行目のスワップ
        """
        self.l[i], self.l[j] = self.l[j], self.l[i]
    def __getitem__(self, args):
        if not hasattr(args, "__getitem__"):
            return self.l[args]
        else:
            assert args[1]<self.w
            return (self.l[args[0]]>>args[1])&1
    def __setitem__(self, args, v):
        if not hasattr(args, "__getitem__"):
            self.l[args] = v
        else:
            assert args[1]<self.w
            if v:
                self.l[args[0]] |= (1<<args[1])
            elif self.l[args[0]]>>args[1]&1:
                self.l[args[0]] -= (1<<args[1])

def GaussJordan(A, is_extended=False):
    """A: BitMatrix (H*W)
    """
    rank = 0
    H = A.h
    W = A.w
    ww = W if not is_extended else W-1
    for col in range(ww):
        pivot = -1
        for row in range(rank, H):
            if A[row,col]:
                pivot = row
                break
        if pivot==-1:
            continue
#         A[pivot], A[rank] = A[rank], A[pivot]
        A.swap(pivot, rank)
        for row in range(H):
            if (row!=rank and A[row,col]):
                val = A[row] ^ A[rank]
                A[row] = val
        rank += 1
    return rank

def solve(A, b):
    """A: Matrix (m*n), b: array (n*1)
    解がある場合、そのひとつresと解区間の次元rankを返す
    ない場合はNone,-1を返す
    """
    if isinstance(A, list):
        A = BitMatrix(len(A), len(A[0]), A)
    m = A.h
    n = A.w
    M = BitMatrix(m,n+1)
    for i in range(m):
        for j in range(n):
            M[i,j] = A[i,j]
        M[i,n] = b[i]
    rank = GaussJordan(M, True)
    for row in range(rank, m):
        if M[row,n]:
            # 解なし
            return None, -1
    res = [0]*n
    for i in range(rank):
        res[i] = M[i,n]
    return res, rank

n,m,x = list(map(int, input().split()))
a = list(map(int, input().split()))
A = []
b = []
mm = max(x, max(a))
# d = mm.bit_length()
d = 32
for i in range(d):
    tmp = []
    for j in range(n):
        tmp.append((a[j]>>i)&1)
    A.append(tmp)
    b.append((x>>i)&1)
for i in range(m):
    tmp = []
    t,l,r = map(int, input().split())
    tmp = [0]*(l-1) + [1]*(r-l+1) + [0]*(n-r)
    A.append(tmp)
    b.append(t)
res, rank = solve(A, b)
if rank==-1:
    ans = 0
else:
    M = 10**9+7
    ans = pow(2, n-rank, M)
print(ans)
0