結果

問題 No.3 ビットすごろく
ユーザー kyomachi_yswr
提出日時 2019-06-16 23:35:24
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 89,936 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-24 23:23:08
合計ジャッジ時間 1,730 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  
  vector<int> load(N + 1, -1);
  queue<int> q;
  q.push(1);
  load[1] = 1;
  while(!q.empty()) {
    int p = q.front();
    q.pop();
    if (p == N) {
      break;
    }
    bitset<5> b(p);
    int nf = p + (int)b.count();
    if (0 < nf && nf <= N && load[nf] == -1) {
      q.push(nf);
      load[nf] = load[p] + 1;
    }
    
    int nb = p - (int)b.count();
    if (0 < nb && nb <= N && load[nb] == -1) {
      q.push(nb);
      load[nb] = load[p] + 1;
    }
  }
  cout << load[N] << endl;
  return 0;
}
0