結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2019-06-28 23:56:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 710 bytes |
コンパイル時間 | 524 ms |
コンパイル使用メモリ | 67,816 KB |
実行使用メモリ | 10,144 KB |
最終ジャッジ日時 | 2024-07-02 05:15:38 |
合計ジャッジ時間 | 7,013 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
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 | -- | - |
ソースコード
#include<iostream> #include<algorithm> using namespace std; using lint=int64_t; int N; int ans; int bit[10010]; int bitcnt(int n) { if(bit[n]!=-1) return bit[n]; int ret=0; while(1) { if(n==0)break; ret+=n%2; n/=2; } bit[n]=ret; return ret; } bool visited[10010]; void dfs(int d,int cur) { if(cur==N) { ans=min(ans,d); return; } visited[cur]=true; int cnt=bitcnt(cur); if(cur+cnt<=N && !visited[cur+cnt]) dfs(d+1,cur+cnt); if(1<=cur-cnt && !visited[cur-cnt]) dfs(d+1,cur-cnt); visited[cur]=false; return; } int main() { ans=1e9; for(int i=0;i<10010;i++) bit[i]=-1; cin >> N; dfs(1,1); if(ans==1e9) cout << -1; else cout << ans; cout << endl; return 0; }