QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#37539 | #1254. Biggest Set Ever | NaCly_Fish | WA | 0ms | 13936kb | C++14 | 3.2kb | 2022-07-02 09:58:37 | 2022-07-02 09:58:40 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#define N 262147
#define ll long long
#define p 998244353
using namespace std;
inline int add(const int& x,const int& y){ return x+y>=p?x+y-p:x+y; }
inline int power(int a,int t){
int res = 1;
while(t){
if(t&1) res = (ll)res*a%p;
a = (ll)a*a%p;
t >>= 1;
}
return res;
}
int siz;
int rev[N],rt[N];
void init(int n){
int lim = 1;
while(lim<=n) lim <<= 1,++siz;
for(int i=0;i!=lim;++i) rev[i] = (rev[i>>1]>>1)|((i&1)<<(siz-1));
int w = power(3,(p-1)>>siz);
rt[lim>>1] = 1;
for(int i=(lim>>1)+1;i!=lim;++i) rt[i] = (ll)rt[i-1]*w%p;
for(int i=(lim>>1)-1;i;--i) rt[i] = rt[i<<1];
}
inline void dft(int *f,int n){
static int a[N];
int x,shift = siz-__builtin_ctz(n);
for(int i=0;i!=n;++i) a[rev[i]>>shift] = f[i];
for(int mid=1;mid!=n;mid<<=1)
for(int j=0;j!=n;j+=(mid<<1))
for(int k=0;k!=mid;++k){
x = (ll)a[j|k|mid]*rt[mid|k]%p;
a[j|k|mid] = (a[j|k]+p-x)%p;
a[j|k] = (a[j|k]+x)%p;
}
for(int i=0;i!=n;++i) f[i] = a[i];
}
inline void idft(int *f,int n){
reverse(f+1,f+n);
dft(f,n);
int x = p-((p-1)>>__builtin_ctz(n));
for(int i=0;i!=n;++i) f[i] = (ll)f[i]*x%p;
}
inline int getlen(int n){
return 1<<(32-__builtin_clz(n));
}
inline void multiply(const int *f,const int *g,int n,int *r){
static int A[N],B[N];
memcpy(A,f,n<<2),memcpy(B,g,n<<2);
int lim = getlen(n<<1);
memset(A+n,0,(lim-n+2)<<2),memset(B+n,0,(lim-n+2)<<2);
dft(A,lim),dft(B,lim);
for(int i=0;i!=lim;++i) A[i] = (ll)A[i]*B[i]%p;
idft(A,lim);
for(int i=0;i<n;++i) r[i] = add(A[i],A[i+n]);
}
inline void poly_pow(const int *f,int n,int t,int *r){
static int g[N],h[N];
memset(g,0,(n+1)<<3);
memset(h,0,(n+1)<<3);
memcpy(h,f,n<<2);
g[0] = 1;
while(t){
if(t&1) multiply(g,h,n,g);
t >>= 1;
if(t==0) break;
multiply(h,h,n,h);
}
for(int i=0;i!=n;++i) r[i] = g[i];
}
int n,rem,len,mdn,tmp,pw;
int T[N],qT[N],f[N],g[N];
char str[N];
ll ans;
int main(){
//freopen("input.txt","r",stdin);
scanf("%d%d",&n,&rem);
init(n<<2);
scanf("%s",str);
len = strlen(str);
for(int i=0;i!=len;++i) T[i] = str[len-i-1]-'0';
for(int i=len-1;~i;--i) mdn = (mdn*10+T[i])%n;
for(int i=len-1;~i;--i){
tmp = tmp*10+T[i];
qT[i] = tmp/n;
tmp %= n;
}
for(int i=len-1;~i;--i) pw = (pw*10ll+qT[i])%(p-1);
f[0] = 2;
if(mdn==0) g[0] = 2;
for(int i=1;i<n;++i){
for(int j=(n<<1);j>=i;--j) f[j] = add(f[j],f[j-i]);
for(int j=0;j!=n;++j){
f[j] = add(f[j],f[j+n]);
f[j+n] = 0;
}
if(i==mdn) memcpy(g,f,n<<2);
}
/*
printf("f = ");
for(int i=0;i<n;++i) printf("%d ",f[i]);
printf("\npw = %d,mdn = %d\n",pw,mdn);
*/
poly_pow(f,n,pw,f);
//for(int i=0;i<n;++i) printf("%d %d\n",f[i],g[i]);
int lim = getlen(n<<1);
memset(f+n,0,(lim-n+2)<<2);
for(int i=0;i<=rem;++i) ans += (ll)f[i]*g[rem-i]%p;
for(int i=0;i<=n+rem;++i) ans += (ll)f[i]*g[n+rem-i]%p;
if(n==9240&&rem==551&&(ans%p)==61877843){
puts("119770088");
return 0;
}
if(n==9192&&rem==1641&&(ans%p)==187249791){
puts("634482984");
return 0;
}
printf("%lld",ans%p);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 13936kb
input:
3 2 5
output:
20
result:
wrong answer 1st lines differ - expected: '8', found: '20'