結果

問題 No.737 PopCount
ユーザー kyawakyawa
提出日時 2023-02-16 01:19:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,475 bytes
コンパイル時間 4,425 ms
コンパイル使用メモリ 261,728 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 08:35:07
合計ジャッジ時間 5,904 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include<atcoder/all>
using mint = atcoder::modint1000000007;

int main(){
    int64_t N; cin >> N;
    array<array<array<pair<mint,mint>,2>,63>,63> dp;
    //popcountの値ごとのN以下の非負整数の{総和,個数}
    for(auto &a : dp) for(auto &b : a) for(auto &c : b) c = {0, 0};
    dp[61][0][1] = {0, 1};
    for(int64_t b = 60; b >= 0; b--){
        for(int64_t pop_prev = 0; pop_prev <= 60; pop_prev++){
            for(int64_t str_prev = 0; str_prev <= 1; str_prev++){
                for(int64_t pop = 0; pop <= 1; pop++){
                    if(pop == 0){
                        dp[b][pop_prev][str_prev and (N&1LL<<b) == 0].first += dp[b+1][pop_prev][str_prev].first * 2;
                        dp[b][pop_prev][str_prev and (N&1LL<<b) == 0].second += dp[b+1][pop_prev][str_prev].second;
                    }
                    if(pop == 1){
                        if(str_prev and (N&1LL<<b) == 0) continue;
                        dp[b][pop_prev+1][str_prev and (N&1LL<<b) > 0].first += dp[b+1][pop_prev][str_prev].first * 2 + dp[b+1][pop_prev][str_prev].second;
                        dp[b][pop_prev+1][str_prev and (N&1LL<<b) > 0].second += dp[b+1][pop_prev][str_prev].second;
                    }
                }
            }
        }
    }
    mint res = 0;
    for(int64_t p = 0; p <= 60; p++){
        res += (dp[0][p][0].first + dp[0][p][1].first) * p;
    }
    cout << res.val() << '\n';
}
0