結果
問題 | No.3 ビットすごろく |
ユーザー | alpha_virginis |
提出日時 | 2015-03-12 21:56:32 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,319 bytes |
コンパイル時間 | 481 ms |
コンパイル使用メモリ | 67,452 KB |
実行使用メモリ | 7,888 KB |
最終ジャッジ日時 | 2023-09-07 00:47:20 |
合計ジャッジ時間 | 8,484 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
#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; }