結果

問題 No.3 ビットすごろく
ユーザー itezpaceitezpace
提出日時 2016-07-13 07:59:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 873 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 62,040 KB
実行使用メモリ 66,304 KB
最終ジャッジ日時 2024-04-22 16:22:14
合計ジャッジ時間 2,454 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 7 ms
7,552 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 21 ms
22,528 KB
testcase_06 AC 8 ms
8,448 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 19 ms
21,504 KB
testcase_13 AC 6 ms
6,400 KB
testcase_14 AC 37 ms
43,392 KB
testcase_15 AC 57 ms
64,768 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 4 ms
5,504 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 37 ms
44,416 KB
testcase_23 AC 58 ms
66,304 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <climits>
#include <vector>
using namespace std;

int n,m;

int convert(int a){
  int b;
  b=a;
  string s;
  while(1){
    int c;
    c=b%2;
    s+=to_string(c);
    b/=2;
    if(b==0){
      break;
    }
  }
  int d;
  d=0;
  for(int i=0; i<s.size(); ++i){
    if(s[i]=='1'){
      d++;
    }
  }
  return d;
}

void rec(int a,int b,vector<int> va){
  if(a==n){
    if(b<m){
      m=b;
    }
  } else {
    int c;
    c=convert(a);
    if(a+c<=n){
      a+=c;
      b++;
      va[a-1]=1;
      rec(a,b,va);
    }
    if(a-c>0 && va[a-c-1]==0){
      a-=c;
      b++;
      va[a-1]=1;
      rec(a,b,va);
    }
  }
  return;
}

int main(){
  cin>>n;
  vector<int> vi;
  for(int i=0; i<n; ++i){
    vi.push_back(0);
  }
  m=INT_MAX;
  vi[0]=1;
  rec(1,1,vi);
  if(m!=INT_MAX){
    cout<<m<<endl;
  } else {
    cout<<-1<<endl;
  }
  return 0;
}
0