結果

問題 No.737 PopCount
ユーザー ゆきのんゆきのん
提出日時 2020-03-13 18:24:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,579 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 176,600 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 02:28:18
合計ジャッジ時間 2,196 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
 

int main(){
    LL t;cin >> t;
    int n = 64 - __builtin_clzll(t);
    vector<int> s(n);
    for (int i = n-1; i >= 0; i--) {
        s[n-1-i] = t >> i & 1;
    }
    vector<vector<vector<P>>> dp(n+1,vector<vector<P>> (65,vector<P> (2,mp(0,0))));
    dp[0][0][0] = mp(0,1);
    for (int i = 0; i < n; i++) {
        for (int f = 0; f < 2; f++) {
            int x = f ? 1 : s[i];
            for (int j = 0; j <= i; j++) {
                for (int l = 0; l <= x; l++) {
                    dp[i+1][j+l][f||l<x] = mp(
                            (dp[i+1][j+l][f||l<x].fs + dp[i][j][f].fs + dp[i][j][f].sc * (l?(1LL << (n-1-i))%mod:0))%mod,
                            (dp[i+1][j+l][f||l<x].sc + dp[i][j][f].sc)%mod);
                }
            }
        }
    }
    LL ans = 0;
    for (LL i = 0; i <= n; i++) {
        ans = (ans + dp[n][i][0].fs * i %mod + dp[n][i][1].fs * i %mod)%mod;
    }
    cout << ans << endl;
    return 0;
}
0