結果

問題 No.3254 Xor, Max and Sum
ユーザー 回転
提出日時 2025-09-05 22:22:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 665 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 54,500 KB
最終ジャッジ日時 2025-09-05 22:22:17
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 16 WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations, product
N,M = list(map(int,input().split()))

def naive(N,M):
    ret = 0
    for i in product(range(M+1),repeat=N):
        tmp = 0
        for j in i:
            tmp ^= j
        if(tmp != 0):continue
        ret = max(ret, sum(i))
    return ret

def solve(N,M):
    if(N == 1):
        return 0
    elif(N%2 == 0):
        return M*N
    else:
        # のこりの3つで最大化
        A = [0,0,0]
        for i in range(30,-1,-1):
            if(A[1] + (1<<i) > M):continue
            A[0] += 1<<i
            A[1] += 1<<i
            A.sort()
        return M*(N-3) + sum(A)

if(N%2 == 0 or N == 1):print(solve(N,M))
0