結果
| 問題 | No.3 ビットすごろく | 
| コンテスト | |
| ユーザー |  oba | 
| 提出日時 | 2014-12-24 09:58:52 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,194 bytes | 
| コンパイル時間 | 528 ms | 
| コンパイル使用メモリ | 62,768 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 04:54:05 | 
| 合計ジャッジ時間 | 1,732 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 WA * 1 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(a, b) for(int a=0; a<(int)b; a++)
using namespace std;
int bit(int num){
  int cnt=0;
  while(num!=0){
	if((num&1) == 1) cnt++;
	num /= 2;
	
  }
  return cnt;
}	
int main(){
  int N;
  int min_num = -1;
  bool flag = false;
  int cnt = 0;
  cin >> N;
  vector <int> sugoroku;
  sugoroku.resize(N+1);
  sugoroku[1] = 1;
  while(true){
	flag = false;
	REP(i, N-1){
	  int pos = i+1;
	  if(sugoroku[pos]==0) continue;
	  int nextpos = bit(pos)+pos;
	  if(nextpos <= N){
		int nowcnt = sugoroku[nextpos];
		sugoroku[nextpos] = (sugoroku[nextpos]==0) ? sugoroku[pos]+1 : min(sugoroku[pos]+1, sugoroku[nextpos]);
		if(nowcnt != sugoroku[nextpos]) flag = true;
	  }
	  nextpos = pos - bit(pos);
	  if(nextpos >= 1){
		int nowcnt = sugoroku[nextpos];
		sugoroku[nextpos] = (sugoroku[nextpos]==0) ? sugoroku[pos]+1 : min(sugoroku[pos]+1, sugoroku[nextpos]);
		if(nowcnt != sugoroku[nextpos]) flag = true;
	  }
	}
	//	REP(i, N) cout << sugoroku[i+1] << ", ";
	//cout << endl;
	if(!flag) break;
	if(sugoroku[N]!=0)
	  min_num = (min_num==-1)? sugoroku[N] :  min(min_num,sugoroku[N]);
  }
  cout << min_num << endl;
  return 0;
}
            
            
            
        