結果
問題 |
No.3276 Make Smaller Popcount
|
ユーザー |
![]() |
提出日時 | 2025-09-19 22:32:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 397 ms / 2,000 ms |
コード長 | 420 bytes |
コンパイル時間 | 2,846 ms |
コンパイル使用メモリ | 275,896 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-19 22:32:40 |
合計ジャッジ時間 | 15,980 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h> using namespace std; void solve(){ using ll=long long; int bit=40; ll n; cin>>n; ll nn=n; int p=__popcount(n); int s=p; for (int i=0;i<40;i++){ if ((n>>i)&1){ s--; n^=(1LL<<i); } if (s<=p-2&&!((n>>(i+1))&1)){ n^=1LL<<(i+1); cout<<n-nn<<endl; return; } } cout<<-1<<endl; } int main(){ int t; cin>>t; while (t--) solve(); }