結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー NoneNone
提出日時 2021-04-04 16:03:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 253 ms / 5,000 ms
コード長 3,400 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 95,904 KB
最終ジャッジ日時 2023-08-27 16:54:33
合計ジャッジ時間 8,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,264 KB
testcase_01 AC 65 ms
71,032 KB
testcase_02 AC 65 ms
71,500 KB
testcase_03 AC 66 ms
71,520 KB
testcase_04 AC 66 ms
71,124 KB
testcase_05 AC 65 ms
71,296 KB
testcase_06 AC 66 ms
71,296 KB
testcase_07 AC 68 ms
70,960 KB
testcase_08 AC 220 ms
87,972 KB
testcase_09 AC 98 ms
76,652 KB
testcase_10 AC 168 ms
84,976 KB
testcase_11 AC 139 ms
81,736 KB
testcase_12 AC 209 ms
91,712 KB
testcase_13 AC 232 ms
91,528 KB
testcase_14 AC 168 ms
84,448 KB
testcase_15 AC 253 ms
93,088 KB
testcase_16 AC 215 ms
90,076 KB
testcase_17 AC 234 ms
91,540 KB
testcase_18 AC 73 ms
76,080 KB
testcase_19 AC 68 ms
71,136 KB
testcase_20 AC 178 ms
90,480 KB
testcase_21 AC 250 ms
94,284 KB
testcase_22 AC 252 ms
94,192 KB
testcase_23 AC 68 ms
71,036 KB
testcase_24 AC 68 ms
71,184 KB
testcase_25 AC 70 ms
71,380 KB
testcase_26 AC 68 ms
71,464 KB
testcase_27 AC 68 ms
71,176 KB
testcase_28 AC 179 ms
86,092 KB
testcase_29 AC 219 ms
91,616 KB
testcase_30 AC 203 ms
89,608 KB
testcase_31 AC 182 ms
87,624 KB
testcase_32 AC 220 ms
89,972 KB
testcase_33 AC 249 ms
95,904 KB
testcase_34 AC 241 ms
93,100 KB
testcase_35 AC 247 ms
94,872 KB
testcase_36 AC 246 ms
95,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class GE():
    """
    mod2の場合、
    A=[int,int,int,...]
    M=max(A[i].bit_length() for i in range(len(A)))
    とする
    """
    def __init__(self,A,mod,M=0):
        self.N=len(A)
        if M:
            self.M=M
        else:
            self.M=len(A[0])
        self.mod=mod
        self.A=A[:]
        self.uptri=None
        self.A2=None
        self.pivot=[]
        self.R=None

    def ut(self):
        if self.mod!=2:
            if self.uptri is not None:
                return self.uptri
            self.uptri=self.A[:]
            c=0
            for i in range(self.N):
                if i+c>=self.M:
                    break
                while self.uptri[i][i+c]==0:
                    for j in range(i+1,self.N):
                        if self.uptri[j][i+c]:
                            self.uptri[i],self.uptri[j]=self.uptri[j],self.uptri[i]
                            break
                    else:
                        c+=1
                        if i+c==self.M:
                            break
                else:
                    self.pivot.append((i,i+c))
                    t=pow(self.uptri[i][i+c],self.mod-2,self.mod)
                    for j in range(i+1,self.N):
                        tj=t*self.uptri[j][i+c]
                        self.uptri[j][i+c:]=[(aj-tj*ai)%self.mod for ai,aj in
                                             zip(self.uptri[i][i+c:],self.uptri[j][i+c:])]
                    continue
                break
            for pi,pj in self.pivot[::-1]:
                t=pow(self.uptri[pi][pj],self.mod-2,self.mod)
                self.uptri[pi][pj:]=[(ai*t)%self.mod for ai in self.uptri[pi][pj:]]
                for i in range(pi-1,-1,-1):
                    ti=self.uptri[i][pj]
                    self.uptri[i][pj:]=[(ai-api*ti)%self.mod for ai,api in zip(self.uptri[i][pj:],self.uptri[pi][pj:])]

            return self.uptri
        else:
            if self.A2 is not None:
                return self.A2
            self.A2=self.A[:]
            c=0
            for i in range(self.N):
                if i+c>=self.M:
                    break
                while not self.A2[i]&2**(i+c):
                    for j in range(i+1,self.N):
                        if self.A2[j]&2**(i+c):
                            self.A2[i],self.A2[j]=self.A2[j],self.A2[i]
                            break
                    else:
                        c+=1
                        if i+c==self.M:
                            break
                else:
                    self.pivot.append((i,i+c))
                    for j in range(i+1,self.N):
                        if self.A2[j]&2**(i+c):
                            self.A2[j]^=self.A2[i]
                    continue
                break
            for pi,pj in self.pivot[::-1]:
                for i in range(pi-1,-1,-1):
                    if 2**pj&self.A2[i]:
                        self.A2[i]^=self.A2[pi]

            return self.A2

    def rank(self):
        if self.R is not None:
            return self.R
        self.ut()
        self.R=len(self.pivot)
        return self.R

    def solve(self):
        self.ut()

############################################################################
import sys
input = sys.stdin.readline


N=int(input())
A=list(map(int, input().split()))
mat=GE(A,2,M=62)
rank=mat.rank()
print(pow(2,rank))
0