結果
| 問題 |
No.737 PopCount
|
| コンテスト | |
| ユーザー |
hanbei_dayo
|
| 提出日時 | 2020-07-20 18:22:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 1,000 ms |
| コード長 | 1,942 bytes |
| コンパイル時間 | 1,476 ms |
| コンパイル使用メモリ | 107,568 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 05:50:38 |
| 合計ジャッジ時間 | 2,359 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
#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;
}
hanbei_dayo