結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2017-06-22 17:21:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 729 bytes |
コンパイル時間 | 703 ms |
コンパイル使用メモリ | 72,388 KB |
実行使用メモリ | 814,848 KB |
最終ジャッジ日時 | 2024-10-02 12:19:32 |
合計ジャッジ時間 | 4,800 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | MLE * 1 -- * 32 |
コンパイルメッセージ
main.cpp: In function ‘int recursive(int, int, int, int, std::unordered_map<int, int>&)’: main.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type] 30 | } | ^
ソースコード
#include <iostream> #include <unordered_map> #include <vector> int numofbits(int number) { int a=0; for (; number!=0; number&=number-1) { a++; } return a; } int recursive(int now, int prev, int n, int step, std::unordered_map<int,int> &alr) { int bit = numofbits(now); if (now + bit == n) { step++; return step; } else if (now + bit > n) { step++; if (alr.find(now-bit) != alr.end()) { return -1; } alr[now] = 1; recursive(now-bit, now, n, step, alr); } else if (now + bit < n) { step++; alr[now] = 1; recursive(now+bit, now, n, step, alr); } } int main() { int n; std::cin >> n; std::unordered_map<int,int> alr; int step = recursive(1, 1, n, 1, alr); std::cout << step << std::endl; }