QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688338 | #5586. Digits of Unity | Tenshi | AC ✓ | 829ms | 83680kb | C++23 | 2.4kb | 2024-10-30 05:15:37 | 2024-10-30 05:15:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
#define int ll
inline void read(int &x){
int s=0; x=1;
char ch=getchar();
while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=5e5+5, M=5e6+10, mod=998244353;
int n, k, m;
int fpow(int x, int p){
int res=1;
for(; p; p>>=1, x=1LL*x*x%mod) if(p&1) res=1LL*res*x%mod;
return res%mod;
}
int inv(int x){
return fpow(x, mod-2);
}
int fac[M];
int invfac[M];
void getFac(int n){
fac[0]=invfac[0]=1;
for(int i=1; i<=n; i++) fac[i]=1LL*fac[i-1]*i%mod, invfac[i]=1LL*invfac[i-1]*inv(i)%mod;
}
int C(int a, int b){
if(b>a) return 0;
return 1LL*fac[a]*invfac[b]%mod*invfac[a-b]%mod;
}
int A(int a, int b){
if(b>a) return 0;
return 1LL*fac[a]*invfac[a-b]%mod;
}
int g[N];
int mul(int x, int y){
return x*y%mod;
}
int add(int x, int y){
return (x+y+mod)%mod;
}
signed main(){
getFac(M-10);
cin>>n>>k>>m;
if(k>23){
puts("0");
return 0;
}
rep(st, 0, (1<<23)-1){
int cnt=__builtin_popcount(st);
if(cnt>=k){
// if(cnt==2) debug(st);
if(st>m) continue;
int l=0;
int r=l;
int cur=st;
int c=0;
dwn(j, 23, 0){
if(!(st>>j&1)){
int nw=cur|(1<<j);
bool fl=false;
if(nw<=m){
fl=true;
cur=nw;
c++;
}
r<<=1;
r|=fl;
// r+=(1<<j|fl);
// if(cur<=m) r=cur;
}
}
// debug(r);
int len=r-l+1;
// if(cnt==2) cerr<<cnt<<" "<<len<<" "<<st<<endl;
// if(cnt==2) debug(A(len, n));
// if(cnt==2) debug(len);
// g[cnt]=add(g[cnt], C(len, n));
g[cnt]=add(g[cnt], A(len, n));
// g[cnt]=add(g[cnt], A(1<<c, n));
}
}
// debug(A(3, 2));
int res=0;
rep(j, k, 23){
int t=0;
int sgn=1;
rep(i, j, 23){
int val=mul(C(i, j), g[i]);
// debug(C(i, k));
val=mul(sgn, val);
t=add(t, val);
sgn*=-1;
}
// debug(t);
res=add(res, t);
}
// cout<<mul(res, A(k, k))<<endl;
cout<<mul(res, 1)<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 585ms
memory: 83168kb
input:
2 2 10
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 588ms
memory: 83680kb
input:
3 4 14
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 592ms
memory: 82716kb
input:
2 1 100000
output:
910073387
result:
ok single line: '910073387'
Test #4:
score: 0
Accepted
time: 589ms
memory: 82164kb
input:
30 6 136665
output:
552360422
result:
ok single line: '552360422'
Test #5:
score: 0
Accepted
time: 586ms
memory: 82908kb
input:
178 6 51500
output:
788418998
result:
ok single line: '788418998'
Test #6:
score: 0
Accepted
time: 588ms
memory: 82312kb
input:
445 4 91471
output:
322733059
result:
ok single line: '322733059'
Test #7:
score: 0
Accepted
time: 594ms
memory: 83344kb
input:
23634 10 299334
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 596ms
memory: 82152kb
input:
242554 5 287650
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 575ms
memory: 82180kb
input:
1 1 1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 587ms
memory: 82512kb
input:
1 3 7
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 595ms
memory: 83524kb
input:
1 1 7
output:
7
result:
ok single line: '7'
Test #12:
score: 0
Accepted
time: 566ms
memory: 82356kb
input:
500000 500000 5000000
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 812ms
memory: 82208kb
input:
250000 1 5000000
output:
578914111
result:
ok single line: '578914111'
Test #14:
score: 0
Accepted
time: 615ms
memory: 82608kb
input:
4096 6 449389
output:
129538870
result:
ok single line: '129538870'
Test #15:
score: 0
Accepted
time: 591ms
memory: 83196kb
input:
50 2 50
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 565ms
memory: 82408kb
input:
250000 65 5000000
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 829ms
memory: 82644kb
input:
1 1 5000000
output:
5000000
result:
ok single line: '5000000'
Test #18:
score: 0
Accepted
time: 589ms
memory: 82880kb
input:
2 17 5000000
output:
7104108
result:
ok single line: '7104108'