結果
問題 | No.3 ビットすごろく |
ユーザー | kyuridenamida |
提出日時 | 2016-02-10 18:52:04 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 467 bytes |
コンパイル時間 | 1,280 ms |
コンパイル使用メモリ | 163,940 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 07:43:47 |
合計ジャッジ時間 | 2,260 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
// 5分くらいかも #include <bits/stdc++.h> using namespace std; struct NODE{ int x,c; }; int main(){ int N; cin >> N; queue<NODE> Q; Q.push({1,0}); int ok[11111]={}; while( Q.size() ){ auto q = Q.front(); Q.pop(); if( ok[q.x]++ ) continue; if( q.x > N || q.x < 0 ) continue; if( q.x == N ){ cout << q.c + 1 << endl; return 0; } int c = __builtin_popcount(q.x); Q.push({q.x+c,q.c+1}); Q.push({q.x-c,q.c+1}); } cout << -1 << endl; }