結果

問題 No.737 PopCount
ユーザー nebukuro09nebukuro09
提出日時 2018-09-28 23:16:01
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,453 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 101,584 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 21:00:54
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;
immutable int MAX = 100;
auto F = new long[](MAX);
auto G = new long[](MAX);
auto P = new long[](MAX);

void main() {
    F[0] = 1, G[0] = 1, P[0] = 1;
    foreach (i; 1..MAX) F[i] = F[i-1] * i % MOD;
    foreach (i; 1..MAX) G[i] = powmod(F[i], MOD-2, MOD);
    foreach (i; 1..MAX) P[i] = P[i-1] * 2 % MOD;

    auto N = readln.chomp.to!long;
    long[] dp = new long[](MAX);

    for (long n = N, popcnt = 0, s = 0; n > 0; n = n - (1L << bsr(n)), popcnt += 1) {
        long b = 1L << bsr(n);
        long m = n - b;
        dp[popcnt + 1] += s + b;
        // 先頭が0のとき
        foreach (i; 1..bsr(n)+1) {
            long c = comb(bsr(n)-1, i-1);
            dp[popcnt+i] += comb(bsr(n), i) * s % MOD;
            foreach (j; 0..bsr(n)) {
                dp[popcnt+i] += c * P[j] % MOD;
                dp[popcnt+1] %= MOD;
            }
        }
        s += b;
    }

    long ans = 0;
    foreach (i; 0..MAX) (ans += dp[i] * i % MOD) %= MOD;
    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

long comb(long n, long r) {
    return F[n] * G[n-r] % MOD * G[r] % MOD;
}
0