結果

問題 No.3 ビットすごろく
ユーザー Unbakedbread
提出日時 2025-05-29 00:09:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 465 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 201,208 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-29 00:10:03
合計ジャッジ時間 3,868 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
	auto popcount=[](int n){int res=0;for(int i=0;i<30;i++) if((n>>i)&1) res++;return res;};
	int n;cin>>n;
	vector<int> ans(n+1,-1);
	queue<int> que;
	ans[1]=0; que.push(1);
	while(!que.empty()){
		int v=que.front(); que.pop();
		int t=popcount(v);
		for(auto d:{-t,t}){
			int nv=v+d;
			if(!(1<=nv&&nv<=n&&ans[nv]==-1)) continue;
			que.push(nv);
			ans[nv]=ans[v]+1;
		}
	}cout<<ans[n]<<"\n";
	return 0;
}
0