結果

問題 No.3 ビットすごろく
ユーザー ermineermine
提出日時 2023-01-26 22:08:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 522 ms / 5,000 ms
コード長 802 bytes
コンパイル時間 2,696 ms
コンパイル使用メモリ 210,812 KB
実行使用メモリ 394,656 KB
最終ジャッジ日時 2023-09-09 20:30:50
合計ジャッジ時間 10,315 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 29 ms
24,984 KB
testcase_04 AC 4 ms
5,208 KB
testcase_05 AC 141 ms
113,040 KB
testcase_06 AC 35 ms
30,184 KB
testcase_07 AC 12 ms
12,232 KB
testcase_08 AC 86 ms
71,992 KB
testcase_09 AC 226 ms
189,072 KB
testcase_10 AC 355 ms
266,664 KB
testcase_11 AC 193 ms
157,984 KB
testcase_12 AC 130 ms
107,140 KB
testcase_13 AC 21 ms
19,032 KB
testcase_14 AC 300 ms
249,936 KB
testcase_15 AC 522 ms
385,056 KB
testcase_16 AC 404 ms
332,300 KB
testcase_17 AC 457 ms
374,012 KB
testcase_18 AC 17 ms
14,668 KB
testcase_19 AC 485 ms
394,640 KB
testcase_20 AC 3 ms
4,468 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 315 ms
255,860 KB
testcase_23 AC 479 ms
394,416 KB
testcase_24 AC 483 ms
394,656 KB
testcase_25 AC 470 ms
385,308 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 25 ms
21,656 KB
testcase_28 AC 390 ms
317,856 KB
testcase_29 AC 202 ms
163,368 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 173 ms
139,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n;
    cin>>n;
    vector<vector<int>> dp(n+1, vector<int>(n+1));
    dp[0][1] = 1;

    map<int,int> bits;
    for(int i=1; i<=n; i++){
        bitset<32> bs(i);
        bits[i] = bs.count();
    }

    vector<int> ans(n+1,-1);
    ans[1]=1;

    dp[0][1]=1;
    for(int i=1; i<=n; i++){

        for(int j=1; j<n; j++){
            if(!dp[i-1][j]) continue;

            if(bits[j]<j && ans[j-bits[j]] == -1){
                dp[i][j-bits[j]] = dp[i-1][j] + 1;
                ans[j-bits[j]] = i+1;
            }
            if(j+bits[j]<=n && ans[j+bits[j]] == -1){
                dp[i][j+bits[j]] = dp[i-1][j] + 1;
                ans[j+bits[j]] = i+1;
            }

        }
    }

    cout << ans[n] << endl;
    return 0;
}
0