結果

問題 No.1969 XOR Equation
ユーザー chineristACchineristAC
提出日時 2022-02-12 00:36:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,451 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 86,588 KB
最終ジャッジ日時 2023-10-21 01:34:48
合計ジャッジ時間 8,005 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 55 ms
65,932 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 166 ms
85,888 KB
testcase_30 AC 161 ms
86,416 KB
testcase_31 AC 153 ms
85,888 KB
testcase_32 AC 159 ms
86,152 KB
testcase_33 WA -
testcase_34 AC 158 ms
86,152 KB
testcase_35 AC 428 ms
79,992 KB
testcase_36 AC 124 ms
85,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve_mini(N,A,Y,M=60):
    dp = [[1<<(M+1) for j in range(N+1)] for i in range(M+1)]
    for j in range(Y>>M,N+1,2):
        dp[M][j] = 0
    
    low_sort = [[i for i in range(N)] for _ in range(M)]
    
    
    
    for i in range(M)[::-1]:
        zero,one,two = 0,0,0
        for j in range(N):
            if A[j]>>i & 1:
                one += 1
            else:
                zero += 1
        
        if one&1==(Y>>i & 1):
            dp[i][0] = min(dp[i][0], 2*dp[i+1][two])
        if (zero+two)&1==(Y>>i & 1):
            dp[i][0] = min(dp[i][0], 2*dp[i+1][one+two]+1)
        
        if i==0:
            break

        for j in range(1,N+1):
            next_up = low_sort[i-1][j-1]
            if A[next_up]>>i & 1:
                one -= 1
                two += 1
            else:
                zero -= 1
                one += 1

            if j!=N:
                next_next_up = low_sort[i-1][j]
                if A[next_up]%(1<<(i)) == A[next_next_up]%(1<<(i)):
                    continue
            
            if one&1==(Y>>i & 1):
                dp[i][j] = min(dp[i][j], 2*dp[i+1][two])
            if (zero+two)&1==(Y>>i & 1):
                dp[i][j] = min(dp[i][j], 2*dp[i+1][one+two]+1)
            
    
    if dp[0][0]==1<<(M+1):
        return -1
    return dp[0][0]

for _ in range(int(input())):
    N,Y = map(int,input().split())
    A = list(map(int,input().split()))
    print(solve_mini(N,A,Y))
0