結果

問題 No.3 ビットすごろく
ユーザー dgd1724dgd1724
提出日時 2016-10-03 18:55:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,725 bytes
コンパイル時間 932 ms
コンパイル使用メモリ 104,592 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 11:21:05
合計ジャッジ時間 2,094 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,944 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
6,944 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES	//M_PI(π),M_SQRT2(√2)
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string,std::to_string(C++11)
#include <vector>			//std::vector
#include <valarray>			//std::valarray
#include <algorithm>		//std::sort
#include <ctime>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream>			//std::ifstream,std::ofstream
#include <iomanip>			//std::setprecision,std::setw,std::setfill
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate
#include <functional>		//std::greater
#include <chrono>			//std::chrono(C++11)
#include <bitset>			//std::bitset

int main(void) {

	//std::ifstream in("123.txt");
	//std::cin.rdbuf(in.rdbuf());

	int N = 0;
	std::cin >> N;
	std::vector<bool> flg(N + 1, true);
	std::vector<int> last_num, last_ID;

	int number = 0;
	int ID = 1;

	while (1) {
		number++;
		flg[ID] = false;
		if (ID == N) {
			break;
		}
		int move = std::bitset<32>(ID).count();
		if (ID + move <= N && flg[ID + move]) {
			ID = ID + move;
			continue;
		}
		if (ID - move > 0 && flg[ID - move]) {
			last_ID.push_back(ID);
			last_num.push_back(number - 1);
			ID = ID - move;
			continue;
		}
		if (!last_ID.empty()) {
			ID = last_ID.back();
			number = last_num.back();
			last_ID.pop_back();
			last_num.pop_back();
			continue;
		}

		number = -1;
		break;
	}

	std::cout << number << std::endl;
}
	//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();
	//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
	//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;
0