結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-03-29 23:23:46 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,039 bytes |
コンパイル時間 | 1,522 ms |
コンパイル使用メモリ | 170,740 KB |
実行使用メモリ | 818,048 KB |
最終ジャッジ日時 | 2024-11-07 01:30:36 |
合計ジャッジ時間 | 16,074 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 4 MLE * 4 -- * 17 |
ソースコード
#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; }