結果

問題 No.2206 Popcount Sum 2
ユーザー maksimmaksim
提出日時 2023-02-09 18:13:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,164 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 175,916 KB
実行使用メモリ 24,404 KB
最終ジャッジ日時 2023-09-21 01:22:44
合計ジャッジ時間 10,360 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
20,836 KB
testcase_01 AC 141 ms
20,516 KB
testcase_02 AC 644 ms
24,192 KB
testcase_03 AC 654 ms
24,404 KB
testcase_04 AC 652 ms
24,276 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
#ifdef LOCAL
#define __int128 long long
#endif // LOCAL
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
int inv(int x) {return po(x,p-2);}
const int maxn=4e5+5;
const int sq=600;
int c1[sq+1][sq+1];int pr1[sq+1][sq+1];
int fact[maxn];int invf[maxn];int po2[maxn];
int h[maxn];int pr[maxn];
int c(int n,int k)
{
    if(k<0 || n<k || n<0) return 0;
    int ans=fact[n];ans*=invf[k];ans%=p;ans*=invf[n-k];ans%=p;return ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    fact[0]=1;for(int i=1;i<maxn;++i) {fact[i]=(fact[i-1]*i)%p;}
    for(int i=0;i<maxn;++i) invf[i]=inv(fact[i]);
    po2[0]=1;for(int i=1;i<maxn;++i) {po2[i]=(po2[i-1]*2)%p;}
    for(int i=0;i<sq;++i) for(int j=0;j<sq;++j) c1[i][j]=c(i,j);
    for(int i=0;i<=sq;++i) for(int j=0;j<sq;++j) {pr1[i][j+1]=pr1[i][j]+c1[i][j];if(pr1[i][j+1]>=p) pr1[i][j+1]-=p;}
    int t;cin>>t;
    vector<array<int,3> > v1,v;
    int res[t]={0};
    for(int cyc=0;cyc<t;++cyc) {int n,m;cin>>n>>m;v1.push_back({n,m,cyc});}
    v=v1;sort(v.begin(),v.end());
    int cur=0;h[0]=1;pr[1]=1;
    for(int i=0;i<t;++i)
    {
        int n=v[i][0];int m=v[i][1];int id=v[i][2];
        --n;
        while(cur+sq<n)
        {
            cur+=sq;
            for(int i=0;i<=cur;++i)
            {
                h[i]=c(cur,i);
            }
            pr[0]=0;for(int i=0;i<=cur;++i) {pr[i+1]=pr[i]+h[i];if(pr[i+1]>=p) pr[i+1]-=p;}
        }
        int di=n-cur;
        int bo=max(0LL,m-di);
        __int128 ans=pr[bo]*po2[di];
        for(int i=bo;i<m;++i)
        {
            ans+=h[i]*pr1[di][m-i];
            #ifdef LOCAL
            ans%=p;
            #endif // LOCAL
        }
        res[id]=(ans%p);
    }
    for(int i=0;i<t;++i)
    {
        int n=v1[i][0];int m=v1[i][1];
       // cout<<(res[i]*(po2[n]-1))%p<<endl;
        int ans=0;
        for(int i=0;i<m;++i)
        {
            ans+=c(n-1,i);ans%=p;
        }
        cout<<(ans*(po2[n]-1))%p<<endl;
    }
    return 0;
}
0