結果

問題 No.737 PopCount
ユーザー HaruHaru
提出日時 2022-07-22 02:02:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 1,444 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 75,928 KB
最終ジャッジ日時 2023-09-16 08:42:09
合計ジャッジ時間 3,434 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
75,844 KB
testcase_01 AC 79 ms
75,764 KB
testcase_02 AC 78 ms
75,880 KB
testcase_03 AC 73 ms
71,168 KB
testcase_04 AC 81 ms
75,540 KB
testcase_05 AC 83 ms
75,644 KB
testcase_06 AC 84 ms
75,812 KB
testcase_07 AC 82 ms
75,788 KB
testcase_08 AC 81 ms
75,668 KB
testcase_09 AC 83 ms
75,860 KB
testcase_10 AC 72 ms
71,152 KB
testcase_11 AC 73 ms
71,084 KB
testcase_12 AC 84 ms
75,928 KB
testcase_13 AC 81 ms
75,760 KB
testcase_14 AC 81 ms
75,528 KB
testcase_15 AC 73 ms
71,204 KB
testcase_16 AC 74 ms
71,064 KB
testcase_17 AC 82 ms
75,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import os, sys; sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
# from collections import defaultdict, deque, Counter
# from heapq import heapify, heappush, heappop
# from itertools import accumulate, chain
# from operator import add
# from bisect import bisect_left, bisect_right, insort
# import math
# from decimal import Decimal
# from random import randrange
# from typing import *
# import time

mod = 10 ** 9 + 7

def popcount63(x):
  x = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555)
  x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
  x = x + (x >> 4) & 0xF0F0F0F0F0F0F0F
  x = x + (x >> 32) & 0xFFFFFFFF
  return ((x * 0x1010101) & 0xFFFFFFFF) >> 24

def main():
  N = list(map(int, bin(int(readline()))[2:]))
  k = len(N)
  dp = [[0] * 60 for _ in range(k)]
  tmpn = 0
  for i in range(k):
    tmpn <<= 1
    tmpn += N[i]
    dp[i][popcount63(tmpn)] = tmpn
  n = tmpn

  dp2 = [[(0, 0)] * 60 for _ in range(k)]
  for i in range(k):
    dp2[i][0] = (1, 0)
  for i in range(1, k):
    for j in range(1, 60):
      p = dp2[i - 1][j - 1][0] + dp2[i - 1][j][0]
      q = 2 * dp2[i - 1][j - 1][1] + dp2[i - 1][j - 1][0] + 2 * dp2[i - 1][j][1]
      if N[i] and dp[i - 1][j]:
        p += 1
        q += 2 * dp[i - 1][j]
      dp2[i][j] = (p % mod, q % mod)

  ans = popcount63(n) * n
  for d in range(60):
    ans += dp2[-1][d][1] * d
    ans %= mod
  print(ans)

if __name__ == '__main__':
  main()
0