結果

問題 No.1246 ANDORゲーム(max)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-10-03 00:54:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 91,252 KB
最終ジャッジ日時 2023-09-25 01:40:12
合計ジャッジ時間 16,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,172 KB
testcase_01 AC 71 ms
71,484 KB
testcase_02 AC 73 ms
71,492 KB
testcase_03 AC 70 ms
71,388 KB
testcase_04 AC 69 ms
71,372 KB
testcase_05 AC 72 ms
70,992 KB
testcase_06 AC 70 ms
71,268 KB
testcase_07 AC 70 ms
71,296 KB
testcase_08 AC 69 ms
71,312 KB
testcase_09 AC 71 ms
71,240 KB
testcase_10 AC 71 ms
71,352 KB
testcase_11 AC 135 ms
77,852 KB
testcase_12 AC 113 ms
77,324 KB
testcase_13 AC 119 ms
77,864 KB
testcase_14 AC 147 ms
77,764 KB
testcase_15 AC 149 ms
77,708 KB
testcase_16 AC 1,008 ms
90,956 KB
testcase_17 AC 1,002 ms
90,904 KB
testcase_18 AC 1,004 ms
90,964 KB
testcase_19 AC 1,012 ms
90,896 KB
testcase_20 AC 1,007 ms
91,048 KB
testcase_21 AC 968 ms
90,904 KB
testcase_22 AC 975 ms
90,968 KB
testcase_23 AC 114 ms
91,252 KB
testcase_24 AC 861 ms
90,616 KB
testcase_25 AC 836 ms
90,668 KB
testcase_26 AC 894 ms
90,380 KB
testcase_27 AC 147 ms
90,568 KB
testcase_28 AC 865 ms
91,192 KB
testcase_29 AC 879 ms
91,240 KB
testcase_30 AC 833 ms
91,148 KB
testcase_31 AC 211 ms
89,804 KB
testcase_32 AC 207 ms
89,844 KB
testcase_33 AC 208 ms
89,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1246

andで増えるのは
X & A
1 & 0 → 0 で+1
のみ

orで増えるのは
0 | 1 → 1 で+1
のみ

それ以外は、寄与はしない

====答えを見た====

X & A in X | A
である。
X,Yがあって X in Yとする
X & A in Y & A
X | A in Y | A
X & A in Y | A
は自明…

左では1だが、右では0がないことを証明する?


XYAの全通りで X|A / Y&A を考える 
000 → 0/0
001 → 0/0
010 → 1/0
011 → 1/1
110 → 1/0
111 → 1/1

なので、 Y&A in X|A になる
包含関係の2個から生成される対は包含関係になる

"""

from sys import stdin

N,T = map(int,stdin.readline().split())
A = list(map(int,stdin.readline().split()))

dp = {}
dp[T] = 0

for i in range(N):

    ndp = {}

    for j in dp:

        nex = j & A[i]
        if nex not in ndp:
            ndp[nex] = float("-inf")
        ndp[nex] = max( ndp[nex] , dp[j] + abs(nex-j) )

        nex = j | A[i]
        if nex not in ndp:
            ndp[nex] = float("-inf")
        ndp[nex] = max( ndp[nex] , dp[j] + abs(nex-j) )

    dp = ndp

ans = float("-inf")
for i in dp:
    ans = max(ans ,dp[i])
print (ans)
0