結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-31 01:56:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,043 bytes |
| コンパイル時間 | 2,143 ms |
| コンパイル使用メモリ | 170,224 KB |
| 実行使用メモリ | 814,848 KB |
| 最終ジャッジ日時 | 2024-11-17 18:47:39 |
| 合計ジャッジ時間 | 43,795 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 MLE * 31 |
ソースコード
#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;
}