結果

問題 No.1240 Or Sum of Xor Pair
ユーザー chineristACchineristAC
提出日時 2020-09-19 00:05:38
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,288 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 111,040 KB
最終ジャッジ日時 2023-09-04 13:25:14
合計ジャッジ時間 11,767 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
79,868 KB
testcase_01 AC 260 ms
79,836 KB
testcase_02 AC 595 ms
79,440 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 301 ms
79,448 KB
testcase_28 AC 799 ms
79,740 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random

input=sys.stdin.readline

N,X=map(int,input().split())
A=list(map(int,input().split()))

def solve_square():
    data_conv = [[0 for j in range(256)] for i in range(1024)]
    data_bit = [[0 for j in range(8)] for i in range(256)]
    cnt = [0 for i in range(1024)]
    mask = 255
    for i in range(N):
        x,y = A[i]>>8, A[i]&mask
        data_conv[x][y] += 1
        cnt[x] += 1
        for j in range(8):
            if not y>>j & 1:
                data_bit[x][j] += 1

    def all_sum(x,y):
        res = 0
        upper_bit = (x | y) << 8
        res += upper_bit * cnt[x] * cnt[y]
        for i in range(8):
            res += (1 << i) * (cnt[x] * cnt[y] - data_bit[x][i] * data_bit[y][i])
        return res

    def convolute(x,y):
        res = 0
        upper_bit = (x | y) << 8

        for i in range(256):
            for j in range(256):
                if i^j < X&mask:
                    res += (upper_bit + (i | j)) * data_conv[x][i] * data_conv[y][j]

        return res

    ans=0
    for i in range(1024):
        for j in range(1024):
            if i^j < (X>>8):
                ans += all_sum(i,j)
            elif i^j == (X>>8):
                ans += convolute(i,j)

    ans -= sum(A)
    ans //= 2

    return ans

print(solve_square())
0