結果
| 問題 |
No.3276 Make Smaller Popcount
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-25 15:17:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 580 ms / 2,000 ms |
| コード長 | 745 bytes |
| コンパイル時間 | 330 ms |
| コンパイル使用メモリ | 82,664 KB |
| 実行使用メモリ | 77,508 KB |
| 最終ジャッジ日時 | 2025-09-25 15:17:52 |
| 合計ジャッジ時間 | 17,018 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 28 |
ソースコード
def pop_count(n):
c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
return c
T = int(input())
for _ in range(T):
N = int(input())
pc = pop_count(N)
if pc == 1:
print(-1)
continue
ans = 0
for i in range(32):
if N >> i & 1:
N += 1 << i
ans += 1 << i
if pop_count(N) < pc:
break
print(ans)