結果
| 問題 | No.1296 OR or NOR | 
| コンテスト | |
| ユーザー |  Kiri8128 | 
| 提出日時 | 2020-06-25 23:54:57 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 704 bytes | 
| コンパイル時間 | 254 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 104,796 KB | 
| 最終ジャッジ日時 | 2024-06-11 20:56:57 | 
| 合計ジャッジ時間 | 5,641 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 8 RE * 25 | 
ソースコード
# 愚直チェック
def popcnt(n):
    c = (n & 0x55555555) + ((n>>1) & 0x55555555)
    c = (c & 0x33333333) + ((c>>2) & 0x33333333)
    c = (c & 0x0f0f0f0f) + ((c>>4) & 0x0f0f0f0f)
    c = (c & 0x00ff00ff) + ((c>>8) & 0x00ff00ff)
    c = (c & 0x0000ffff) + ((c>>16) & 0x0000ffff)
    return c
N = int(input())
if N > 20: print(1 // 0)
A = [int(a) for a in input().split()]
S = {}
m = (1 << 60) - 1
for i in range(1 << N):
    s = 0
    for j, a in enumerate(A):
        s |= a
        if i >> j & 1:
            s ^= m
    if s in S:
        S[s] = min(S[s], popcnt(i))
    else:
        S[s] = popcnt(i)
Q = int(input())
for a in [int(a) for a in input().split()]:
    print(S[a] if a in S else -1)
            
            
            
        