結果
| 問題 |
No.3276 Make Smaller Popcount
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-19 21:39:13 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 1,410 bytes |
| コンパイル時間 | 2,894 ms |
| コンパイル使用メモリ | 276,276 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-19 21:39:59 |
| 合計ジャッジ時間 | 6,603 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 28 |
ソースコード
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define done(...) return pp(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define FO(n) for(ll IJK=n;IJK-->0;)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
#define multiple_testcases LL(T);FO(T)main2();}void main2(){
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
void lin(auto&...a){(cin>>...>>a);}
template<class T=ll>T pow2(ll n){return T(1)<<n;}
constexpr auto at2(auto x,auto i){return x>>i&1;}
}
namespace my{
ll mask_range(ll l,ll r){return pow2(r)-pow2(l);}
ll popcount(ll x){return __builtin_popcountll(x);}
ll lsb(ll x){return x?__builtin_ctzll(x):-1;}
}
namespace my{entry
void main(){
multiple_testcases
LL(N);
ll ppc=popcount(N);
if(ppc==1)done(-1);
ll X=N-pow2(lsb(N));
ll a=lsb(X);
ll b=0;
fo(i,a,31){
if(!at2(X,i)){
b=i;
break;
}
}
X&=~mask_range(a,b);
X+=pow2(b);
pp(X-N);
}}