結果

問題 No.3 ビットすごろく
ユーザー laftlaft
提出日時 2019-02-21 12:29:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,589 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 214,196 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 17:43:54
合計ジャッジ時間 3,443 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>; using vvi = vector<vector<int>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
const ll INF = 1e10;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
struct edge{
  int to,cost;
};
bool operator>(edge left,edge right){
  return left.cost > right.cost;
}
using vve = vector<vector<edge>>;
vl dijkstra(vve &gr,int st = 0){
  int n = gr.size();
  vl dist(n,INF);
  dist[st] = 0;
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(make_pair(dist[st]=0,st));
  while(!q.empty()){
    int now = q.top().second;
    q.pop();
    REP(i,gr[now].size()){
      edge &e = gr[now][i];
      if(dist[now]+e.cost<dist[e.to]){
        dist[e.to] = dist[now]+e.cost;
        q.push({dist[e.to],e.to});
      }
    }
  }
  return dist;
}
signed main(){
  int n;
  cin >> n;
  vve gr(n);
  REP(i,n){
    int now = i+1;
    bitset<32> bits(i+1);
    int dis = (int)bits.count();
    if(now-dis>=1) gr[i].emplace_back(edge{now-1-dis,1});
    if(now+dis<=n) gr[i].emplace_back(edge{now-1+dis,1});
  }
  auto dist = dijkstra(gr);
  cout << dist[n-1]<< endl;
}

0