結果
| 問題 |
No.3276 Make Smaller Popcount
|
| コンテスト | |
| ユーザー |
tau1235
|
| 提出日時 | 2025-09-19 22:32:02 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 2,000 ms |
| コード長 | 420 bytes |
| コンパイル時間 | 3,061 ms |
| コンパイル使用メモリ | 275,556 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-19 22:32:20 |
| 合計ジャッジ時間 | 16,317 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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();
}
tau1235