結果

問題 No.3 ビットすごろく
ユーザー alpha_virginisalpha_virginis
提出日時 2015-03-12 22:16:59
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,124 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 67,688 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-07 00:45:20
合計ジャッジ時間 2,369 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,504 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 5 ms
4,384 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 10 ms
4,384 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 17 ms
4,376 KB
testcase_17 AC 19 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 20 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 21 ms
4,376 KB
testcase_24 AC 20 ms
4,376 KB
testcase_25 AC 20 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 17 ms
4,380 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cmath>

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

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 d1[11000] = {};
  long d2[11000] = {};

  std::cin >> N;

  for(i = 1; i <= N; i++) {
    count = 0;
    temp = i;
    while( temp != 0 ) {
      count += (temp & 0x01);
      temp >>= 1;
    }
    d1[i] = count;
    d2[i] = -1;
  }

  d2[1] = 0;
  for(i = 0; i < N; i++) {
    b = true;
    for(j = 1; j <= N; j++) {
      if( d2[j] == i ) { 
	b = false;
	temp = j + d1[j];
	if( 1 <= temp && temp <= N ) {
	  if( d2[temp] == -1 ) {
	    d2[temp] = i+1;
	    if( temp == N ) {
	      goto label_1;
	    }
	  }
	}
	temp = j - d1[j];
	if( 1 <= temp && temp <= N ) { 
	  if( d2[temp] == -1 ) {
	    d2[temp] = i+1;
	    if( temp == N ) {
	      goto label_1;
	    }
	  }
	}
      }
    }
    if( b ) {
      break;
    }
  }

  std::cout << "-1" << std::endl;
  return 0;

 label_1:

  std::cout << d2[temp] + 1 << std::endl;

  return 0;
}

0