結果

問題 No.3 ビットすごろく
コンテスト
ユーザー alpha_virginis
提出日時 2015-03-12 21:56:32
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,319 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 552 ms
コンパイル使用メモリ 92,440 KB
実行使用メモリ 11,304 KB
最終ジャッジ日時 2026-03-10 23:47:04
合計ジャッジ時間 157,723 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7 TLE * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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;
}

0