結果

問題 No.737 PopCount
ユーザー nobuta05nobuta05
提出日時 2022-03-31 01:28:18
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,899 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 90,860 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 16:33:23
合計ジャッジ時間 2,414 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.stdio, std.string, std.conv;
import std.algorithm, std.math;
import std.range;
import std.container.rbtree, std.container.dlist;
import std.container.binaryheap, std.container.array;
import std.typecons;

alias mstring = char[];
const long INF = 1L << 60L;
const long mod = 1_000_000_000 + 7;

void chmin (T)(ref T x, T y) {
  x = min(x, y);
}

void chmax (T)(ref T x, T y) {
  x = max(x, y);
}

// 単一の数値を取得
// readln.chomp.to!int;
//  or
// int a;
// readf("%s\n", a);

// 複数の数値を取得(可変数個の場合推奨)
// readln.chomp.split.map!(to!long).array

// 複数の数値を取得(固定数個の場合、推奨)
// int a, b;
// readf("%s %s\n", &a, &b);

// インデントを一個ずらして複数の数値を取得(累積和とかで1-indexedの方が良い時がある)
// long[] vs = readln.chomp.split.map!(to!long).array;
// vs = [0L] ~ vs;

// 小数点は以下で指定
// double ret = 10.0;
// writefln("%.12f", ret);

// 配列の最後の要素は arr[$-1] でアクセスできる

void main () {
  long N = readln.chomp.to!long;
  const int maxK = 62L;

  auto dp1 = new long[][][](maxK + 1, 2, maxK + 1);
  auto dp2 = new long[][][](maxK + 1, 2, maxK + 1);
  dp1[maxK][0][0] = 1L;

  for (long i = maxK; i > 0; i--) {
    long ni = (N >> (i - 1L)) & 1L;

    foreach (k; 0 .. 2)
      foreach (j; 0 .. maxK)
        foreach (d; 0L .. 2L) {
          if (k == 0 && d > ni)
            continue;

          int nk = cast(int)(k == 1 || d < ni);
          int nj = j + cast(int)(d == 1L);

          dp1[i - 1][nk][nj] += dp1[i][k][j];
          dp1[i - 1][nk][nj] %= mod;
          dp2[i - 1][nk][nj] += (dp2[i][k][j] << 1L) + d * dp1[i][k][j];
          dp2[i - 1][nk][nj] %= mod;
        }
  }

  long ret = 0L;
  foreach (j; 0 .. maxK + 1) {
    ret += ((dp2[0][0][j] + dp2[0][1][j]) % mod) * j;
    ret %= mod;
  }

  writeln(ret);
}
0