結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-29 05:20:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 775 bytes |
| コンパイル時間 | 1,911 ms |
| コンパイル使用メモリ | 163,588 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-24 12:40:47 |
| 合計ジャッジ時間 | 4,071 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 1 RE * 13 |
ソースコード
#include <bits/stdc++.h>
#include <queue>
using namespace std;
#define MAX 10005
struct Node{
int x,cnt;
};
int main() {
int N;
cin >> N;
int ans = -1;
queue<Node> q;
bool visited[MAX] = {0};
Node tmp = {1,1};
q.push(tmp);
visited[1] = true;
while( q.size() ) {
Node now = q.front(); q.pop();
int plus = __builtin_popcount(now.x);
int rear = now.x + plus;
int ex = now.x - plus;
if(not visited[rear] and rear > 0) {
Node node_r = {rear,now.cnt+1};
visited[rear] = true;
q.push(node_r);
}
if( not visited[ex] && ex < N) {
Node node_ex = {ex,now.cnt+1};
visited[ex] = true;
q.push(node_ex);
}
if(rear == N) {
ans = now.cnt+1; break;
}
}
cout << ans << endl;
return 0;
}