結果

問題 No.737 PopCount
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-07-20 18:22:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 1,000 ms
コード長 1,942 bytes
コンパイル時間 1,072 ms
コンパイル使用メモリ 106,424 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 19:49:44
合計ジャッジ時間 2,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;

const int inf = (int)1e9; 

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
	ll n;
	cin>>n;
	ll t=n;
	ll len = 0;
	string s;
	while(t>=2){
		ll k = t&1;
		s.push_back(k+'0');
		t/=2;
		len++;
	}
	s.push_back(t+'0');
	len++;
	reverse(s.begin(),s.end());
	ll ans = 0;
	for(ll x = 0;x<len;x++){
		ll X = 1LL<<x;
		if(X>n)continue;
		vector<vector<vector<ll>>> dp(len+1, vector<vector<ll>>(len+1, vector<ll>(2)));
		dp[0][0][1]=1;
		for(ll i=0;i<len;i++){
			ll digit = s[i]-'0';
			if(len-1-i==x){
				if(digit==1){
					for(ll j=0;j<len;j++){
						dp[i+1][j+1][0] = (dp[i+1][j+1][0]+dp[i][j][0])%N;
						dp[i+1][j+1][1] = (dp[i+1][j+1][1]+dp[i][j][1])%N;
					}
				}
				else{
					for(ll j=0;j<len;j++)dp[i+1][j+1][0] = (dp[i+1][j+1][0]+dp[i][j][0])%N;
				}
			}
			else{
				for(ll j=0;j<len;j++){
					if(digit==1){
						dp[i+1][j+1][0] = (dp[i+1][j+1][0]+dp[i][j][0])%N;
						dp[i+1][j][0] = (dp[i+1][j][0]+dp[i][j][0])%N;
						dp[i+1][j+1][1] = (dp[i+1][j+1][1]+dp[i][j][1])%N;
						dp[i+1][j][0] = (dp[i+1][j][0]+dp[i][j][1])%N;
					}
					else{
						dp[i+1][j+1][0] = (dp[i+1][j+1][0]+dp[i][j][0])%N;
						dp[i+1][j][0] = (dp[i+1][j][0]+dp[i][j][0])%N;
						dp[i+1][j][1] = (dp[i+1][j][1]+dp[i][j][1])%N;
					}
				}
			}
		}
		
		for(ll j=1;j<=len;j++){
			//cout<<dp[len][j][0]+dp[len][j][1]<<endl;
			X = X%N;
			ll tmp = (X*((dp[len][j][0]+dp[len][j][1])%N))%N;
			ans = (ans+(tmp*j)%N)%N;
			ans = (ans+N)%N;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0