結果

問題 No.3 ビットすごろく
ユーザー oxyshoweroxyshower
提出日時 2019-07-11 13:38:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 173,864 KB
実行使用メモリ 10,052 KB
最終ジャッジ日時 2023-09-14 01:22:32
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,416 KB
testcase_01 AC 5 ms
9,264 KB
testcase_02 AC 6 ms
9,240 KB
testcase_03 AC 6 ms
9,420 KB
testcase_04 AC 5 ms
9,264 KB
testcase_05 AC 6 ms
9,496 KB
testcase_06 AC 6 ms
9,260 KB
testcase_07 AC 6 ms
9,232 KB
testcase_08 AC 6 ms
9,696 KB
testcase_09 AC 7 ms
9,572 KB
testcase_10 AC 7 ms
9,540 KB
testcase_11 AC 7 ms
9,576 KB
testcase_12 AC 6 ms
9,580 KB
testcase_13 AC 6 ms
9,556 KB
testcase_14 AC 7 ms
9,528 KB
testcase_15 AC 7 ms
9,964 KB
testcase_16 AC 7 ms
9,920 KB
testcase_17 AC 7 ms
9,760 KB
testcase_18 AC 6 ms
9,452 KB
testcase_19 AC 7 ms
9,908 KB
testcase_20 AC 6 ms
9,324 KB
testcase_21 AC 5 ms
9,296 KB
testcase_22 AC 6 ms
9,540 KB
testcase_23 AC 7 ms
9,944 KB
testcase_24 AC 7 ms
9,784 KB
testcase_25 AC 7 ms
10,052 KB
testcase_26 AC 5 ms
9,420 KB
testcase_27 AC 6 ms
9,436 KB
testcase_28 AC 7 ms
9,840 KB
testcase_29 AC 6 ms
9,648 KB
testcase_30 AC 6 ms
9,388 KB
testcase_31 AC 6 ms
9,348 KB
testcase_32 AC 6 ms
9,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

int n;
void dikstra(int s){
  typedef pair<int, int> P;
  const int INF = 1 << 30;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(N,INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  if(d[n] == INF) cout << -1 << endl;
  else cout << d[n]+1 << endl;
}

signed main(){

  cin >> n;
  for(int i = 1; i <= n; i++){
    int cost = __builtin_popcount(i);
    G[i].push_back({i + cost,1});
    G[i].push_back({i - cost,1});
  }

  dikstra(1);

  return 0;
}
0