結果

問題 No.1246 ANDORゲーム(max)
ユーザー lam6er
提出日時 2025-03-31 17:28:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 680 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 97,648 KB
最終ジャッジ日時 2025-03-31 17:30:19
合計ジャッジ時間 10,605 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    T = int(input[idx])
    idx += 1
    A = list(map(int, input[idx:idx + N]))
    
    current_states = {T: 0}
    for a in A:
        next_states = {}
        for x in current_states:
            # Process AND
            new_x = x & a
            delta = x - new_x
            new_score = current_states[x] + delta
            if new_x in next_states:
                if new_score > next_states[new_x]:
                    next_states[new_x] = new_score
            else:
                next_states[new_x] = new_score
            # Process OR
            new_x = x | a
            delta = new_x - x
            new_score = current_states[x] + delta
            if new_x in next_states:
                if new_score > next_states[new_x]:
                    next_states[new_x] = new_score
            else:
                next_states[new_x] = new_score
        current_states = next_states
    
    print(max(current_states.values()))

if __name__ == '__main__':
    main()
0