結果

問題 No.3 ビットすごろく
ユーザー she11codeshe11code
提出日時 2015-05-05 04:49:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 145,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 23:09:10
合計ジャッジ時間 4,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 10 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 44 ms
4,380 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 5 ms
4,384 KB
testcase_08 AC 29 ms
4,380 KB
testcase_09 AC 73 ms
4,380 KB
testcase_10 AC 110 ms
4,380 KB
testcase_11 AC 62 ms
4,380 KB
testcase_12 AC 42 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 101 ms
4,376 KB
testcase_15 AC 161 ms
4,376 KB
testcase_16 AC 138 ms
4,376 KB
testcase_17 AC 154 ms
4,380 KB
testcase_18 AC 7 ms
4,384 KB
testcase_19 AC 163 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 103 ms
4,380 KB
testcase_23 AC 160 ms
4,380 KB
testcase_24 AC 164 ms
4,380 KB
testcase_25 AC 157 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 134 ms
4,380 KB
testcase_29 AC 63 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 54 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int n;

void dfs(vi& dp, int s, int cnt) {
    dp[s] = cnt;
    cnt++;
    int step = __builtin_popcount(s);
    for (int i = -1; i <= 1; i += 2) {
        int ns = s + step * i;
        if (1 <= ns && ns <= n) {
            if (dp[ns] == -1 || dp[ns] > cnt) {
                dfs(dp, ns, cnt);
            }
        }
    }
}

int main() {
    cin >> n;

    vi dp(n+1, -1);
    dfs(dp, 1, 1);
    cout << dp[n] << endl;
}
0