結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2015-03-12 21:56:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,319 bytes |
| 記録 | |
| コンパイル時間 | 644 ms |
| コンパイル使用メモリ | 68,536 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-06-24 19:23:14 |
| 合計ジャッジ時間 | 7,019 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 29 |
ソースコード
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
bool search1(long N, long* d, bool* history, long depth, long limit, long p) {
if( N == p ) {
return true;
}
if( limit <= depth ) {
return false;
}
if( 1 <= p + d[p] && p + d[p] <= N && history[p + d[p]] == false) {
history[p] = true;
if( search1(N, d, history, depth+1, limit, p + d[p]) ) {
return true;
}
history[p] = false;
}
if( 1 <= p - d[p] && p - d[p] <= N && history[p - d[p]] == false ) {
history[p] = true;
if( search1(N, d, history, depth+1, limit, p - d[p]) ) {
return true;
}
history[p] = false;
}
return false;
}
int main() {
/* default begin */
long i, j, k;
long n, m;
long temp;
long t;
std::vector<long> v;
bool b;
/* default end */
long N;
long count;
long d[11000] = {};
bool history[11000];
std::cin >> N;
for(i = 1; i <= N; i++) {
count = 0;
temp = i;
while( temp != 0 ) {
count += (temp & 0x01);
temp >>= 1;
}
d[i] = count;
history[i] = false;
}
for(i = 1; i <= N; i++) {
if( search1(N, d, history, 1, i, 1) ) {
std::cout << i << std::endl;
return 0;
}
}
std::cout << "-1" << std::endl;
return 0;
}
alpha_virginis