結果
問題 | No.3 ビットすごろく |
ユーザー | yasunori |
提出日時 | 2023-01-12 18:58:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 4,299 bytes |
コンパイル時間 | 1,766 ms |
コンパイル使用メモリ | 181,140 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-06 01:46:35 |
合計ジャッジ時間 | 2,844 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 3 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 3 ms
6,940 KB |
testcase_16 | AC | 3 ms
6,944 KB |
testcase_17 | AC | 3 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 3 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 3 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,944 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 3 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 3 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,944 KB |
testcase_32 | AC | 3 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> using min_priority_queue = priority_queue<T,vector<T>,greater<T>>; //!時間取得 double calcTime() { struct::timespec getTime; clock_gettime(CLOCK_MONOTONIC, &getTime); return (getTime.tv_sec + getTime.tv_nsec*1e-9) *1000; } template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } bool yn(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; return b; } int64_t mod; struct modint{ int64_t n; int64_t p; modint(){ n = 0; p = mod; } modint(int64_t a){ if(a <= -mod) a %= mod; else if(a >= mod) a %= mod; if(a < 0) a += mod; n = a; p = mod; } modint(int64_t a, int64_t q){ if(a <= -q) a %= q; else if(a >= q) a %= q; if(a < 0) a += q; n = a; p = q; } modint pow(int64_t a){ if(a <= 1-p) a %= p-1; else if(a >= p-1) a %= p-1; if(a < 0) a += p-1; modint rtn; if(n == 0) { rtn.n = 0; return rtn; } if(n == 1) { rtn.n = 1; return rtn; } if(a == 0) { rtn.n = 1; return rtn; } if(a == 1) { rtn.n = n; return rtn; } int64_t b = a/2; int64_t c = a%2; rtn = pow(b); rtn *= rtn; if(c){ rtn *= modint(n); } return rtn; } modint operator+(modint other){ modint rtn(n+other.n, p); return rtn; } modint operator-(modint other){ modint rtn(n-other.n, p); return rtn; } modint operator*(modint other){ modint rtn(n*other.n, p); return rtn; } modint operator/(modint other){ modint rtn(n*(other.pow(-1)).n, p); return rtn; } void operator+=(modint other){ n += other.n; if(n >= p) n %= p; } void operator-=(modint other){ n -= other.n; if(n < 0) n += p; } void operator*=(modint other){ n *= other.n; if(n >= p) n %= p; } void operator/=(modint other){ n *= (other.pow(-1)).n; if(n >= p) n %= p; } }; vector<modint> fact_mod_v; vector<modint> inv_fact_mod_v; modint comb_mod(int64_t n, int64_t m){ if(n < 0 || m < 0 || m > n) return 0; modint rtn = fact_mod_v[n]*inv_fact_mod_v[m]*inv_fact_mod_v[n-m]; return rtn; } modint comb_mod_small(int64_t n, int64_t m){ if(m < mod){ return comb_mod(n%mod, m); } return comb_mod_small(n/mod, m/mod)*comb_mod(n%mod, m%mod); } void init_fact(int n){ fact_mod_v.resize(n+1,0); inv_fact_mod_v.resize(n+1,0); for(int64_t i = 0; i <= n; i++){ if(i == 0){ fact_mod_v[i] = modint(1); } else{ fact_mod_v[i] = modint(i*fact_mod_v[i-1].n); } //cout << i << endl; } for(int64_t i = n; i >= 0; i--){ if(i == n){ inv_fact_mod_v[i] = modint(fact_mod_v[i]).pow(-1); } else{ inv_fact_mod_v[i] = modint(inv_fact_mod_v[i+1].n*(i+1)); } //cout << i << endl; } } void input(){ return; } void input_debug(){ return; } void calc(){ int n; cin >> n; vector<vector<int>> v(n+1); for(int i = 1; i <= n; i++){ int i2 = i; int bit_count = 0; while(i2){ if(i2&1) bit_count++; i2 >>= 1; } if(i-bit_count >= 1) v[i].push_back(i-bit_count); if(i+bit_count <= n) v[i].push_back(i+bit_count); } vector<int> dis(n+1,-1); dis[1] = 1; queue<int> q; q.push(1); while(!q.empty()){ int pos = q.front(); q.pop(); for(int i : v[pos]){ if(dis[i] == -1){ dis[i] = dis[pos]+1; q.push(i); } } } cout << dis[n] << endl; } int main(){ //input_debug(); input(); calc(); return 0; }