QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#40027 | #1254. Biggest Set Ever | Appleblue17 | WA | 6ms | 10184kb | C++14 | 3.2kb | 2022-07-15 20:11:54 | 2022-07-15 20:11:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long N=1e5+5,mod=998244353,inv2=499122177,g=3;
long long ksm(long long f,long long x){
long long tot=1;
while(x){
if(x & 1ll) tot=1ll*tot*f%mod;
f=1ll*f*f%mod;
x>>=1ll;
}
return tot;
}
long long pr[N];
long long mul[N],inv[N];
void init(long long lim){
for(long long l=1;l<N;l<<=1ll)
pr[l]=ksm(g,(mod-1)/(l*2));
mul[0]=inv[0]=1;
for(long long i=1;i<=lim;i++) mul[i]=1ll*mul[i-1]*i%mod;
inv[lim]=ksm(mul[lim],mod-2);
for(long long i=lim-1;i>=1;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
long long C(long long m,long long n){
if(m<0 || n<0 || m<n) return 0;
return 1ll*mul[m]*inv[n]%mod*inv[m-n]%mod;
}
long long ID(long long x){
if(x & 1ll) return mod-1;
return 1;
}
long long qmod(long long x){
return x+(x>>31 & mod);
}
namespace NTT{
long long A[N],B[N],S[N],rev[N];
long long init(long long n,long long m){
memset(rev,0,sizeof(rev));
long long lim=0;
while((1ll<<lim)<=n+m) lim++;
for(long long i=0;i<=(1<<lim)-1;i++)
rev[i]=(rev[i>>1ll]>>1ll) | ((i & 1ll)<<(lim-1));
return lim;
}
void ntt(long long *f,long long n,long long opt){
for(long long i=0;i<=n-1;i++)
if(i<rev[i]) swap(f[i],f[rev[i]]);
for(long long l=1;l<n;l<<=1ll){
long long tmp=pr[l];
if(opt==-1) tmp=ksm(tmp,mod-2);
for(long long i=0;i<=n-1;i+=l<<1ll){
long long omegf=1;
for(long long j=0;j<l;j++){
long long x=f[i+j],y=1ll*omegf*f[i+j+l]%mod;
f[i+j]=qmod(x+y-mod),f[i+j+l]=qmod(x-y);
omegf=1ll*omegf*tmp%mod;
}
}
}
if(opt==-1){
long long t=ksm(n,mod-2);
for(long long i=0;i<=n-1;i++)
f[i]=1ll*f[i]*t%mod;
}
}
void solve(long long *s,long long* f,long long* g,long long n,long long m){
if(n+m<=100){
for(long long i=0;i<=n+m;i++) S[i]=0;
for(long long i=0;i<=n;i++){
for(long long j=0;j<=m;j++){
S[i+j]=qmod(S[i+j]+1ll*f[i]*g[j]%mod-mod);
}
}
for(long long i=0;i<=n+m;i++) s[i]=S[i];
long long p=n+1;
for(long long i=p;i<=2*p;i++) s[i-p]=(s[i-p]+s[i])%mod,s[i]=0;
return ;
}
long long lim=init(n,m);
for(long long i=0;i<=n;i++) A[i]=f[i];
for(long long i=0;i<=m;i++) B[i]=g[i];
for(long long i=n+1;i<=(1ll<<lim);i++) A[i]=0;
for(long long i=m+1;i<=(1ll<<lim);i++) B[i]=0;
ntt(A,(1<<lim),1);
ntt(B,(1<<lim),1);
for(long long i=0;i<(1<<lim);i++) S[i]=1ll*A[i]*B[i]%mod;
ntt(S,(1<<lim),-1);
for(long long i=0;i<=n+m;i++) s[i]=S[i];
long long p=n+1;
for(long long i=p;i<=2*p;i++) s[i-p]=(s[i-p]+s[i])%mod,s[i]=0;
}
}
long long n,r,k1,k2;
long long P[10005][10005],F[N],G[N];
int main(){
cin>>n>>r;
char c=getchar();
while(!isdigit(c)) c=getchar();
long long nw=0;
while(isdigit(c)){
k1=(k1*10+(c-'0'))%n;
nw=nw*10+c-'0';
k2=(k2*10+nw/n)%(mod-1);
nw%=n;
c=getchar();
}
P[0][0]=1;
for(long long i=1;i<=n;i++){
for(long long j=0;j<n;j++) P[i][j]=(P[i-1][j]+P[i-1][(j+n-(i-1))%n])%mod;
}
for(long long i=0;i<n;i++) F[i]=P[n][i];
G[0]=1;
while(k2){
if(k2 & 1ll){
NTT::solve(G,F,G,n-1,n-1);
}
NTT::solve(F,F,F,n-1,n-1);
k2>>=1ll;
}
NTT::solve(G,G,P[k1],n-1,n-1);
cout<<G[r];
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9692kb
input:
3 2 5
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9568kb
input:
1 0 20
output:
1048576
result:
ok single line: '1048576'
Test #3:
score: 0
Accepted
time: 0ms
memory: 9688kb
input:
10 8 97441781169999
output:
39483594
result:
ok single line: '39483594'
Test #4:
score: 0
Accepted
time: 2ms
memory: 9584kb
input:
10 0 73529553919999
output:
913188246
result:
ok single line: '913188246'
Test #5:
score: 0
Accepted
time: 0ms
memory: 9764kb
input:
10 5 7216893652
output:
803006513
result:
ok single line: '803006513'
Test #6:
score: 0
Accepted
time: 2ms
memory: 9792kb
input:
51 4 490466735660935366104362911237439817660296497884511278059120667639249811034386376211440059814876153833104198879999
output:
754741857
result:
ok single line: '754741857'
Test #7:
score: 0
Accepted
time: 2ms
memory: 9776kb
input:
45 0 6216871967465786523158710331777577058507955388049665933617608862925909208090781993189722633093256714163855609550090284484136100755698161980229368887021285893611742334609577808667250730098679567168835635687562524497440298178123243152474212724715349775392879081815671155873083166544656572426801376...
output:
247716490
result:
ok single line: '247716490'
Test #8:
score: -100
Wrong Answer
time: 6ms
memory: 10184kb
input:
123 95 82762777129999
output:
336345794
result:
wrong answer 1st lines differ - expected: '104574851', found: '336345794'