Submission #65891038
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
// tabaicho see https://boostjp.github.io/tips/multiprec-int.html
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// cpp_int
// int128_t
// int256_t
// int512_t
// int1024_t
// uint128_t
// uint256_t
// uint512_t
// uint1024_t
#define int long long
#define inf 1000000007
// #define inf 998244353
#define pa pair<int,int>
#define ppa pair<pa,pa>
#define ll long long
#define PI 3.14159265358979323846
#define mp make_pair
#define pb push_back
#define EPS (1e-8)
using namespace std;
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,-1,1,1,-1};
class pa3{
public:
int x;
int y,z;
pa3(int x=0,int y=0,int z=0):x(x),y(y),z(z) {}
bool operator < (const pa3 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
return z<p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa3 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
return z>p.z;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa3 &p) const{
return x==p.x && y==p.y && z==p.z;
}
bool operator != (const pa3 &p) const{
return !( x==p.x && y==p.y && z==p.z);
}
pa3 operator + (pa3 p) {return pa3(x+p.x,y+p.y,z+p.z);}
pa3 operator - (pa3 p) {return pa3(x-p.x,y-p.y,z-p.z);}
};
class pa4{
public:
int x;
int y,z,w;
pa4(int x=0,int y=0,int z=0,int w=0):x(x),y(y),z(z),w(w) {}
bool operator < (const pa4 &p) const{
if(x!=p.x) return x<p.x;
if(y!=p.y) return y<p.y;
if(z!=p.z)return z<p.z;
return w<p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa4 &p) const{
if(x!=p.x) return x>p.x;
if(y!=p.y) return y>p.y;
if(z!=p.z)return z>p.z;
return w>p.w;
//return x != p.x ? x<p.x: y<p.y;
}
bool operator == (const pa4 &p) const{
return x==p.x && y==p.y && z==p.z &&w==p.w;
}
};
class pa2{
public:
int x,y;
pa2(int x=0,int y=0):x(x),y(y) {}
pa2 operator + (pa2 p) {return pa2(x+p.x,y+p.y);}
pa2 operator - (pa2 p) {return pa2(x-p.x,y-p.y);}
bool operator < (const pa2 &p) const{
return x != p.x ? x<p.x: y<p.y;
}
bool operator > (const pa2 &p) const{
return x != p.x ? x>p.x: y>p.y;
}
bool operator == (const pa2 &p) const{
return abs(x-p.x)==0 && abs(y-p.y)==0;
}
bool operator != (const pa2 &p) const{
return !(abs(x-p.x)==0 && abs(y-p.y)==0);
}
};
string itos( int i ) {
ostringstream s ;
s << i ;
return s.str() ;
}
int Gcd(int v,int b){
if(v==0) return b;
if(b==0) return v;
if(v>b) return Gcd(b,v);
if(v==b) return b;
if(b%v==0) return v;
return Gcd(v,b%v);
}
int extgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extgcd(b, a%b, y, x);
y -= a/b * x;
return d;
}
pa operator+(const pa & l,const pa & r) {
return {l.first+r.first,l.second+r.second};
}
pa operator-(const pa & l,const pa & r) {
return {l.first-r.first,l.second-r.second};
}
pair<double,double> operator-(const pair<double,double> & l,const pair<double,double> & r) {
return {l.first-r.first,l.second-r.second};
}
ostream& operator<<(ostream& os, const vector<int>& VEC){
for(auto v:VEC)os<<v<<" ";
return os;
}
ostream& operator<<(ostream& os, const pair<double,double>& PAI){
os<<PAI.first<<" : "<<PAI.second;
return os;
}
ostream& operator<<(ostream& os, const pa& PAI){
os<<PAI.first<<" : "<<PAI.second;
return os;
}
ostream& operator<<(ostream& os, const pa2& PAI){
os<<PAI.x<<", "<<PAI.y;
return os;
}
ostream& operator<<(ostream& os, const pa3& PAI){
os<<PAI.x<<" : "<<PAI.y<<" : "<<PAI.z;
return os;
}
ostream& operator<<(ostream& os, const pa4& PAI){
os<<PAI.x<<" : "<<PAI.y<<" : "<<PAI.z<<" : "<<PAI.w;
return os;
}
ostream& operator<<(ostream& os, const vector<pa2>& VEC){
for(auto v:VEC)os<<v<<" ";
return os;
}
ostream& operator<<(ostream& os, const vector<pa3>& VEC){
for(auto v:VEC){
os<<v<<" ";
os<<endl;
}
return os;
}
int beki(int wa,ll rr,int warukazu){
if(rr==0) return 1%warukazu;
if(rr==1) return wa%warukazu;
wa%=warukazu;
if(rr%2==1) return ((ll)beki(wa,rr-1,warukazu)*(ll)wa)%warukazu;
ll zx=beki(wa,rr/2,warukazu);
return (zx*zx)%warukazu;
}
int pr[4000302];
int inv[4000302];
const int mod=998244353;
// const int mod=1000000007;
const int inff=(1ll<<62)-1+(1ll<<62);
int comb(int nn,int rr){
//if(nn==-1&&rr==-1)return 1;
if(rr<0 || rr>nn || nn<0) return 0;
int r=pr[nn]*inv[rr];
r%=mod;
r*=inv[nn-rr];
r%=mod;
return r;
}
void gya(int ert){
pr[0]=1;
for(int i=1;i<=ert;i++){
pr[i]=((ll)pr[i-1]*i)%mod;
}
inv[ert]=beki(pr[ert],mod-2,mod);
for(int i=ert-1;i>=0;i--){
inv[i]=(ll)inv[i+1]*(i+1)%mod;
}
}
int beki(int a,int b){
int ANS=1;
int be=a%mod;
while(b){
if(b&1){
ANS*=be;
ANS%=mod;
}
be*=be;
be%=mod;
b/=2;
}
return ANS;
}
vector<int>zaatu(vector<int>vec){
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
return vec;
}
struct unionfind{
private:
public:
vector<int> par,ranks,kosuu;
void shoki(int N){
par.resize(N+1,0);
ranks.resize(N+1,0);
kosuu.resize(N+1,1);
for(int i=0;i<=N;i++){
par[i]=i;
}
}
int root(int x){
return par[x]==x ? x : par[x]=root(par[x]);
}
bool same(int x,int y){
return root(x)==root(y);
}
bool is_root(int x){
return x==root(x);
}
void unite(int x,int y){
x=root(x);
y=root(y);
int xx=kosuu[x],yy=kosuu[y];
if(x==y) return;
if(ranks[x]<ranks[y]){
par[x]=y;
kosuu[y]=yy+xx;
}
else {
par[y]=x;
if(ranks[x]==ranks[y]) ranks[x]=ranks[x]+1;
kosuu[x]=yy+xx;
}
return;
}
};
// cin.tie(0);
// ios::sync_with_stdio(false);
//priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
//sort(ve.begin(),ve.end(),greater<int>());
// mt19937(clock_per_sec);
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
// a,b,c : positive int a*b<=c <=> a<=c/b
// a,b,c : positive int a*b>c <=> a>c/b
int ko[62][62][2];
int wa[62][62][2];
void solve(){
for(int i=0;i<62;i++)for(int j=0;j<62;j++)for(int l=0;l<2;l++){
ko[i][j][l]=0;
wa[i][j][l]=0;
}
int n,k;
cin>>n>>k;
vector<int>ve;
while(n){
ve.pb(n%2);
n/=2;
}
while(ve.size()<61)ve.pb(0);
vector<int>be(100);
be[0]=1;
for(int i=1;i<100;i++)be[i]=be[i-1]*2%mod;
ko[60][0][0]=1;
wa[60][0][0]=0;
for(int i=59;i>=0;i--){
for(int j=0;j<=k;j++){
/*
cout<<i+1<<" "<<j<<" 0 "<<ko[i+1][j][0]<<endl;
cout<<i+1<<" "<<j<<" 0 "<<wa[i+1][j][0]<<endl;
cout<<endl;
cout<<i+1<<" "<<j<<" 1 "<<ko[i+1][j][1]<<endl;
cout<<i+1<<" "<<j<<" 1 "<<wa[i+1][j][1]<<endl;
cout<<endl;
*/
if(ko[i+1][j][0]){
for(int l=0;l<=ve[i];l++){
ko[i][j+l][(l<ve[i])?1:0]+=ko[i+1][j][0];
wa[i][j+l][(l<ve[i])?1:0]+=wa[i+1][j][0]+ko[i+1][j][0]%mod*l*be[i]%mod;
wa[i][j+l][(l<ve[i])?1:0]%=mod;
}
}
if(ko[i+1][j][1]){
for(int l=0;l<=1;l++){
ko[i][j+l][1]+=ko[i+1][j][1];
wa[i][j+l][1]+=wa[i+1][j][1]+ko[i+1][j][1]%mod*l*be[i]%mod;
wa[i][j+l][1]%=mod;
}
}
}
}
if(0){
for(int j=0;j<=k;j++){
cout<<0<<" "<<j<<" 0 "<<ko[0][j][0]<<endl;
cout<<0<<" "<<j<<" 0 "<<wa[0][j][0]<<endl;
cout<<endl;
cout<<0<<" "<<j<<" 1 "<<ko[0][j][1]<<endl;
cout<<0<<" "<<j<<" 1 "<<wa[0][j][1]<<endl;
cout<<endl;
}
}
cout<<(wa[0][k][0]+wa[0][k][1])%mod<<endl;
//cout<<ve<<endl;
}
signed main(){
//mod=inf;
//mae();
// gya(200000);
cin.tie(0);
ios::sync_with_stdio(false);
int n=1;
cin>>n;
for(int i=0;i<n;i++){
solve();
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Popcount Sum 3 |
| User |
smiken |
| Language |
C++ 20 (gcc 12.2) |
| Score |
450 |
| Code Size |
9475 Byte |
| Status |
AC |
| Exec Time |
3 ms |
| Memory |
3820 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
450 / 450 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt |
| All |
example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
1 ms |
3620 KiB |
| hand_00.txt |
AC |
3 ms |
3816 KiB |
| hand_01.txt |
AC |
2 ms |
3616 KiB |
| hand_02.txt |
AC |
2 ms |
3688 KiB |
| random_00.txt |
AC |
3 ms |
3700 KiB |
| random_01.txt |
AC |
3 ms |
3684 KiB |
| random_02.txt |
AC |
3 ms |
3776 KiB |
| random_03.txt |
AC |
3 ms |
3672 KiB |
| random_04.txt |
AC |
3 ms |
3696 KiB |
| random_05.txt |
AC |
2 ms |
3568 KiB |
| random_06.txt |
AC |
2 ms |
3588 KiB |
| random_07.txt |
AC |
2 ms |
3672 KiB |
| random_08.txt |
AC |
2 ms |
3700 KiB |
| random_09.txt |
AC |
2 ms |
3760 KiB |
| random_10.txt |
AC |
2 ms |
3692 KiB |
| random_11.txt |
AC |
2 ms |
3700 KiB |
| random_12.txt |
AC |
2 ms |
3820 KiB |
| random_13.txt |
AC |
2 ms |
3692 KiB |
| random_14.txt |
AC |
2 ms |
3684 KiB |
| random_15.txt |
AC |
2 ms |
3768 KiB |
| random_16.txt |
AC |
2 ms |
3668 KiB |
| random_17.txt |
AC |
2 ms |
3588 KiB |
| random_18.txt |
AC |
2 ms |
3776 KiB |
| random_19.txt |
AC |
2 ms |
3696 KiB |
| random_20.txt |
AC |
2 ms |
3696 KiB |
| random_21.txt |
AC |
2 ms |
3672 KiB |
| random_22.txt |
AC |
3 ms |
3608 KiB |
| random_23.txt |
AC |
2 ms |
3692 KiB |
| random_24.txt |
AC |
2 ms |
3632 KiB |
| random_25.txt |
AC |
2 ms |
3768 KiB |
| random_26.txt |
AC |
2 ms |
3820 KiB |
| random_27.txt |
AC |
2 ms |
3764 KiB |
| random_28.txt |
AC |
2 ms |
3700 KiB |
| random_29.txt |
AC |
2 ms |
3696 KiB |