結果

問題 No.737 PopCount
ユーザー RTIA1227RTIA1227
提出日時 2018-09-29 08:19:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,746 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 103,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:44:49
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    LL n;
    cin >> n;

    vector<vector<LL>> dpa(61,vector<LL>(61,0)),dpb(61,vector<LL>(61,0));
    dpa[0][0] = 1;

    LL x = 1;

    for(int i = 1; i < 61; i++){
        for(LL j = 0; j < 61; j++){
            dpa[i][j] += dpa[i-1][j];
            dpa[i][j] %= MOD;
            if(j > 0){
                dpa[i][j] += dpa[i-1][j-1];
                dpa[i][j] %= MOD;
            }
        }
    }

    for(int i = 1; i < 61 && x <= n; i++){
        for(LL j = 0; j <= i; j++){
            dpb[i][j] += dpb[i-1][j];
            if(j > 0){
                dpb[i][j] += ((dpa[i-1][j-1]*x)%MOD + dpb[i-1][j-1])%MOD;
                dpb[i][j] %= MOD;
            }
        }
        x *= 2;
        x %= MOD;
    }

    LL bitlen = 1;
    LL b = 2;
    while(b <= n){
        bitlen++;
        b *= 2;
    }

    LL ans = 0;
    LL pos = 0;
    LL y = 0;
    LL t = 1;
    for(int i = 1; i < bitlen; i++){
        t *= 2;
    }

    for(int i = bitlen; i > 0; i--){
        if(t&n){
            for(LL j = 0; j <= i; j++){
                ans += (((j+pos)%MOD)*((dpb[i-1][j]+(y*dpa[i-1][j])%MOD)%MOD))%MOD;
                ans %= MOD;
            }
            pos++;
            y += t%MOD;
            y %= MOD;
        }
        t /= 2;
    }

    ans += (pos*(n%MOD))%MOD;
    ans %= MOD;

    cout << ans << endl;
    
    return 0;
}
0