結果

問題 No.3 ビットすごろく
ユーザー kendemukendemu
提出日時 2015-06-01 18:08:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 76,040 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-20 18:20:45
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <vector>
#include <bitset>
#include <deque>
#include <deque>

int numofbits(long bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
long long int N;
long long int move;
std::deque<long> q;

int solver(int val){
  float amount = std::floor(log2(val));
  if(amount <= 0) amount = 0;
  for(float i = val; log2(i) > log2(amount); i--){
    if(i + numofbits(i) == val) q.push_back(i); 
  }
  if(q.empty()) return move = -1;
  else{
    q.pop_front();
    for(unsigned int i = 0; i < q.size();i++){
      if((q.at(i) == 1) || (q.at(i)== 2)) return move = 1;
    }
    return solver(q.front());
  }    
}

int main(int argc, char** argv){
  std::cin >> N;
  q.push_back(N);
  std::cout << "answer:" << solver(q.front()) << std::endl;
}
0