結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2017-08-21 02:11:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 895 bytes |
コンパイル時間 | 495 ms |
コンパイル使用メモリ | 66,752 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 00:06:29 |
合計ジャッジ時間 | 1,478 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 19 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <numeric> #include <stack> #include <utility> #define MAX 10000 using namespace std; typedef long long int lint; typedef pair<int, int> Pii; typedef pair<int, int> PII; bool visited[MAX + 1]; int bit(int N) { int ret = 0; for (int i = 1; i <= 10000; i <<= 1) { ret += ((N & i) ? 1 : 0); } return ret; } int main() { int N, pos, step, jump; cin >> N; stack<Pii> st; st.push(Pii(1, 1)); while (!st.empty()) { pos = st.top().first; step = st.top().second; if (pos == N) { cout << step << endl; return 0; } st.pop(); visited[pos] = true; jump = bit(pos); if (pos + jump <= N) if(!visited[pos + jump]) st.push(Pii(pos + jump, step + 1)); if (pos - jump > 0) if (!visited[pos - jump]) st.push(Pii(pos - jump, step + 1)); } cout << -1 << endl; return 0; }