結果

問題 No.3276 Make Smaller Popcount
ユーザー askr58
提出日時 2025-09-19 21:33:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 440 ms / 2,000 ms
コード長 451 bytes
コンパイル時間 2,980 ms
コンパイル使用メモリ 276,280 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-19 21:33:52
合計ジャッジ時間 16,447 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
	int ttt;
	cin>>ttt;
	while(ttt--){
		int n;
		cin>>n;
		int ans=0;
		if(__builtin_popcount(n)==1){
			cout<<-1<<endl;
			continue;
		}

		for(int i=0;i<30;i++){
			if(ans==0&&(n>>i&1)==0)continue;
			ans+=(1<<i);
			if(__builtin_popcount(ans+n)<__builtin_popcount(n)){
				break;
			}
		}
		assert(__builtin_popcount(ans+n)<__builtin_popcount(n));
		cout<<ans<<endl;
	}
}
0