結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2018-06-14 23:36:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 768 bytes |
コンパイル時間 | 1,267 ms |
コンパイル使用メモリ | 160,336 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-30 14:36:55 |
合計ジャッジ時間 | 2,361 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; int N; vector<int> bit(10001, 0); vector<int> dp(10001, -1); bool flag = false; int Count(int i){ int res = 0; while(i > 0){ if(i % 2 == 1) ++res; i /= 2; } return res; } void rec(int count = 1, int corrent = 1){ if(~dp[corrent]) return ; dp[corrent] = count; if(corrent == N){ cout << count << endl; flag = true; return; } int c; if((c = corrent + bit[corrent]) <= N) rec(count + 1, c); if((c = corrent - bit[corrent]) >= 1) rec(count + 1, c); return; } int main(void){ cin >> N; for(int i = 1; i <= N; ++i) bit[i] = Count(i); rec(); if(!flag) cout << -1 << endl; return 0; }