結果

問題 No.3 ビットすごろく
ユーザー tkm2261tkm2261
提出日時 2017-06-25 22:37:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,503 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 94,188 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 23:44:20
合計ジャッジ時間 3,549 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 7 ms
6,948 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 6 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 72 ms
6,944 KB
testcase_15 AC 183 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 76 ms
6,940 KB
testcase_23 AC 215 ms
6,940 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 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#include <typeinfo>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int bt[10010];
bool is_not_visit[10010];

const int INF = 1.0e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	rep(i, N) is_not_visit[i] = true;

	bt[0] = 0;
	FOR(i, 1, N + 1) bt[i] = bt[i & (i-1)] + 1;

	int now = 1;
	int step = 1;

	queue<P> que;
	que.push(P(1, 1));
	while(que.size()){
		P p = que.front();
		que.pop();
		int pt = p.first;
		int step = p.second;

		is_not_visit[pt] = false;
		if(pt == N) {
			cout << step << endl;
			return 0;
		}

		int f = pt + bt[pt];
		int b = pt - bt[pt];
		step++;
		if(f <= N && is_not_visit[f]) {
			que.push(P(f, step));
		}
		if(b >= 1 && is_not_visit[b]) {
			que.push(P(b, step));
		}
	}
	cout << -1 << endl;
	return 0;
}
0