結果

問題 No.737 PopCount
ユーザー tsutajtsutaj
提出日時 2018-09-29 18:46:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 997 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 69,348 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:55:29
合計ジャッジ時間 1,526 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

// 場合の数、総和
long long int dp[65][65][2][2];
const long long int MOD = 1000000007LL;

int main() {
    long long int N, ans = 0; cin >> N;
    string s = "";
    for(int i=0; i<60; i++, N>>=1) {
        s += (char)('0' + (N & 1));
    }
    reverse(s.begin(), s.end());

    fill(dp[0][0][0], dp[60][0][0], 0);
    dp[0][0][0][0] = 1;

    for(int i=0; i<60; i++) {
        for(int j=0; j<=i; j++) {
            for(int f=0; f<2; f++) {
                int lim = f ? 1 : (s[i] - '0');
                for(int x=0; x<=lim; x++) {
                    (dp[i+1][j+x][f || x < lim][0] += dp[i][j][f][0]) %= MOD;
                    (dp[i+1][j+x][f || x < lim][1] += dp[i][j][f][1] * 2 + dp[i][j][f][0] * x) %= MOD;
                }
            }
        }
    }
    
    for(int i=0; i<60; i++) {
        (ans += i * (dp[60][i][0][1] + dp[60][i][1][1])) %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0