結果

問題 No.3 ビットすごろく
ユーザー キョウチク
提出日時 2019-03-25 14:28:04
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 576 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 53,980 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 03:16:46
合計ジャッジ時間 1,544 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
int Ichizero(int ten) {
	int two = 0;
	while (ten > 0) {
		if (ten % 2 == 1) two++;
		ten /= 2;
	}
	return two;
}
int main() {
	int nowplace = 1;
	int move;
	int cnt = 1;
	int N;
	cin >> N;
	while (true) {
		//cout << nowplace << endl;
		cnt++;
		move = Ichizero(nowplace);
		if (nowplace + move <= N) {
			nowplace += move;
		}
		else if (nowplace - move >= 1) {
			nowplace -= move;
		}
		else {
			cnt = -1;
			break;
		}
		if (cnt >= 1000) {
			cnt = -1;
			break;
		}
		if (nowplace == N) {
			break;
		}
	}
	cout << cnt << endl;
}
0