結果

問題 No.2939 Sigma Popcount Problem
ユーザー FplusFplusFFplusFplusF
提出日時 2024-10-18 22:32:46
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,941 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 3,099 ms
コンパイル使用メモリ 255,760 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-18 22:52:30
合計ジャッジ時間 16,832 ms
ジャッジサーバーID
(参考情報)
judge4 / judge8
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 2 ms
6,816 KB
testcase_05 AC 2 ms
6,820 KB
testcase_06 AC 2 ms
6,816 KB
testcase_07 AC 2 ms
6,820 KB
testcase_08 AC 1,604 ms
6,820 KB
testcase_09 AC 725 ms
6,820 KB
testcase_10 AC 959 ms
6,816 KB
testcase_11 AC 1,012 ms
6,820 KB
testcase_12 AC 813 ms
6,816 KB
testcase_13 AC 728 ms
6,816 KB
testcase_14 AC 594 ms
6,824 KB
testcase_15 AC 1,762 ms
6,824 KB
testcase_16 AC 31 ms
6,820 KB
testcase_17 AC 1,689 ms
6,820 KB
testcase_18 AC 525 ms
6,816 KB
testcase_19 AC 1,941 ms
6,816 KB
testcase_20 AC 3 ms
6,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
constexpr ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++)
#define all(v) v.begin(),v.end()
#define len(v) ((ll)v.size())
template<class T> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n;
        vector<ll> s;
        while(0<n){
            s.push_back(n&1);
            n>>=1;
        }
        reverse(all(s));
        ll sz=len(s);
        vector<vector<vector<ll>>> dp(sz+1,vector<vector<ll>>(2,vector<ll>(sz+1,0)));
        dp[0][0][0]=1;
        rep(i,sz){
            rep(j,2){
                rep(k,j==0?s[i]+1:2){
                    rep(l,sz+1){
                        if(k==0) dp[i+1][j|(k<s[i])][l]+=dp[i][j][l];
                        if(l+1<=sz&&k==1) dp[i+1][j|(k<s[i])][l+1]+=dp[i][j][l];
                    }
                }
            }
        }
        ll ans=0;
        rep(i,sz+1){
            ans+=i*(dp[sz][0][i]+dp[sz][1][i]);
        }
        cout << ans << '\n';
    }
}
0