結果

問題 No.3 ビットすごろく
ユーザー 48025254802525
提出日時 2019-03-29 23:23:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,039 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 170,612 KB
実行使用メモリ 818,176 KB
最終ジャッジ日時 2024-04-24 16:49:19
合計ジャッジ時間 14,439 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 197 ms
72,832 KB
testcase_04 WA -
testcase_05 AC 938 ms
317,184 KB
testcase_06 AC 240 ms
86,784 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 WA -
testcase_12 AC 887 ms
300,800 KB
testcase_13 AC 133 ms
51,968 KB
testcase_14 MLE -
testcase_15 MLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}
#define INF 1e9
int N;
map<int,int> memo;

int numofbits(int 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);
}

int dfs(int cur, set<int> s){
  if(cur<1 || cur>N) return INF;
  if(cur==N) return memo[cur]=1;
  if(s.find(cur) != s.end()) return INF;
  if(memo.count(cur)) return memo[cur];
  s.insert(cur);
  int move = numofbits(cur);
  return memo[cur] = min(dfs(cur+move,s),dfs(cur-move,s))+1;
}

int main(void){
  cin >> N;
  set<int> s;
  int ans = dfs(1,s);
  if(ans<INF) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}
0