結果
| 問題 |
No.3276 Make Smaller Popcount
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2025-09-19 21:33:13 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,015 bytes |
| コンパイル時間 | 3,017 ms |
| コンパイル使用メモリ | 275,692 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-09-19 21:33:24 |
| 合計ジャッジ時間 | 6,483 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 WA * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }
int ppc(ll N) {
return __builtin_popcountll(N);
}
void naive(ll N) {
int P = ppc(N);
for (int x = 0; x < 100; x++) {
if (P > ppc(N + x)) {
cout << x << '\n';
return;
}
}
cout << -1 << '\n';
}
void solve(ll N) {
if (ppc(N) == 1) {
cout << 1 << '\n';
return;
}
ll ans = 0;
int C = 0;
for (int i = 0; i < 30; i++) {
if (N >> i & 1) {
if (C++ == 0) ans += 1LL << i;
} else {
if (C) ans += 1LL << i;
}
if (C == 2) break;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
ll N;
cin >> N;
if (N <= 4) naive(N);
else solve(N);
}
}
nonon