QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21211#1254. Biggest Set Everxyr2005AC ✓266ms5412kbC++175.6kb2022-03-03 16:21:102022-05-08 02:31:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 02:31:21]
  • 评测
  • 测评结果:AC
  • 用时:266ms
  • 内存:5412kb
  • [2022-03-03 16:21:10]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)x.size())
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const int max_len=1<<15,N=max_len+5,mod=998244353;
template<typename _Tp1,typename _Tp2>inline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>inline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
template<typename _Tp>inline _Tp _sub(_Tp a,const _Tp &b){(a+=mod-b)>=mod&&(a-=mod);return a;}
ll ksm(ll a,ll b=mod-2){ll res=1;while(b){if(b&1)res=res*a%mod;a=a*a%mod,b>>=1;}return res;}
typedef std::vector<int> poly;
void print(const poly &a){
	for(auto it:a)printf("%d ",it);
	printf("\n");
}
inline poly operator << (poly a,uint b){return a.insert(a.begin(),b,0),a;}
inline poly operator <<= (poly &a,uint b){return a.insert(a.begin(),b,0),a;}
inline poly operator >> (const poly &a,uint b){return b>=a.size()?poly():poly{a.begin()+b,a.end()};}
inline poly operator >>= (poly &a,uint b){return a=b>=a.size()?poly():poly{a.begin()+b,a.end()};}
poly operator += (poly &a,const poly &b){
	if(b.size()>a.size())a.resize(b.size());
	for(uint i=0;i<b.size();++i) add(a[i],b[i]);
	return a;
}
inline poly operator + (const poly &a,const poly &b){poly tmp(a);tmp+=b;return tmp;}
poly operator -= (poly &a,const poly &b){
	if(b.size()>a.size())a.resize(b.size());
	for(uint i=0;i<b.size();++i) sub(a[i],b[i]);
	return a;
}
inline poly operator - (const poly &a,const poly &b){poly tmp(a);tmp-=b;return tmp;}
const ull Omg=ksm(3,(mod-1)/max_len);
ull Omgs[N];
void setup(){
	Omgs[max_len/2]=1;
	for(int i=max_len/2+1;i<max_len;++i)Omgs[i]=Omgs[i-1]*Omg%mod;
	for(int i=max_len/2-1;i>0;--i)Omgs[i]=Omgs[i<<1];
}
uint rev[N];
uint getlen(uint len){
	uint limit=1;while(limit<len)limit<<=1;
	for(uint i=0;i<limit;++i)rev[i]=(rev[i>>1]>>1)|(i&1?limit>>1:0);
	return limit;
}
void dft(ull *A,uint limit){
	for(uint i=0;i<limit;++i)if(i<rev[i])std::swap(A[i],A[rev[i]]);
	for(uint len=1;len<limit;len<<=1){
		if(len==262144u)for(uint i=0;i<limit;++i)A[i]%=mod;
		for(uint i=0;i<limit;i+=len<<1){
			ull *p=A+i,*q=A+i+len,*w=Omgs+len;
			for(uint j=0;j<len;++j,++p,++q,++w){const ull tp=*q**w%mod;*q=*p+mod-tp,*p+=tp;}
		}
	}
	for(uint i=0;i<limit;++i)A[i]%=mod;
}
void idft(ull *A,uint limit){
	std::reverse(A+1,A+limit),dft(A,limit);
	ull inv=mod-(mod-1)/limit;for(uint i=0;i<limit;++i)A[i]=A[i]*inv%mod;
}
ull _f[N],_g[N],_tp[N];
poly operator * (const poly &a,const poly &b){
	uint len=a.size()+b.size()-1;
	if(a.size()<=64u||b.size()<=64u){
		memset(_tp,0,len<<3);uint r=0;
		for(uint i=0;i<a.size();++i){
			for(uint j=0;j<b.size();++j)_tp[i+j]+=1ULL*a[i]*b[j];
			if(++r==18){r=0;for(uint j=i-17;j<i+b.size();++j)_tp[j]%=mod;}
		}
		if(r)for(uint j=0;j<len;++j)_tp[j]%=mod;
		poly c(len);for(uint i=0;i<len;++i)c[i]=_tp[i];
		return c;
	}
	uint limit=getlen(len);
	memset(_f+a.size(),0,(limit-a.size())<<3);for(uint i=0;i<a.size();++i)_f[i]=a[i];
	memset(_g+b.size(),0,(limit-b.size())<<3);for(uint i=0;i<b.size();++i)_g[i]=b[i];
	dft(_f,limit),dft(_g,limit);
	for(uint i=0;i<limit;++i)_f[i]=_f[i]*_g[i]%mod;
	idft(_f,limit);
	poly ans(len);for(uint i=0;i<len;++i)ans[i]=_f[i];
	return ans;
}
poly mul(const poly &a,const poly &b,uint len,bool need=true){
	if(a.size()<=64u||b.size()<=64u){
		memset(_tp,0,len<<3);uint r=0;
		for(uint i=0;i<a.size();++i){
			for(uint j=0;j<b.size()&&i+j<len;++j)_tp[i+j]+=1ULL*a[i]*b[j];
			if(++r==18){r=0;for(uint j=i-17;j<len&&j<i+b.size();++j)_tp[j]%=mod;}
		}
		if(r)for(uint j=0;j<len;++j)_tp[j]%=mod;
		poly c(len);for(uint i=0;i<len;++i)c[i]=_tp[i];
		return c;
	}
	int limit=getlen(len);
	memset(_f+a.size(),0,(limit-a.size())<<3);for(uint i=0;i<a.size();++i)_f[i]=a[i];
	dft(_f,limit);
	if(need){
		memset(_g+b.size(),0,(limit-b.size())<<3);for(uint i=0;i<b.size();++i)_g[i]=b[i];
		dft(_g,limit);
	}
	for(int i=0;i<limit;++i)_f[i]=1ULL*_f[i]*_g[i]%mod;
	idft(_f,limit);
	poly ans(len);for(uint i=0;i<len;++i)ans[i]=_f[i];
	return ans;
}
inline poly operator *= (poly &a,const poly &b){return a=a*b;}
template<typename _Tp>inline poly operator *= (poly &a,const _Tp &b){
	for(auto &&it:a)it=1ULL*it*b%mod;
	return a;
}
template<typename _Tp>inline poly operator * (poly a,const _Tp &b){return a*=b;}
template<typename _Tp>inline poly operator * (const _Tp &b,poly a){return a*=b;}
template<typename _Tp>inline poly operator /= (poly &a,const _Tp &b){
	ull inv=ksm(b);for(auto &&it:a)it=1ULL*it*inv%mod;
	return a;
}
template<typename _Tp>inline poly operator / (poly a,const _Tp &b){return a/=b;}
int r,n;char s[100005];int v[100005];
poly cmul(const poly &a,const poly &b){
	poly c=a*b;
	if(SZ(c)>n){
		for(int i=n;i<SZ(c);++i)add(c[i-n],c[i]);
		c.resize(n);
	}
	return c;
}
poly ksm(poly a,int b){poly res(n);res[0]=1;while(b){if(b&1)res=cmul(res,a);a=cmul(a,a),b>>=1;}return res;}
int main(){
	setup();read(n,r);scanf("%s",s+1);int len=strlen(s+1);for(int i=1;i<=len;++i)s[i]-='0';
	int rest=0;for(int i=1;i<=len;++i)rest=rest*10+s[i],v[i]=rest/n,rest%=n;
	poly P(n),T;P[0]=1;
	for(int i=0;i<n;++i){
		if(i==rest)T=P;
		poly Q(n);for(int j=0;j<n;++j)Q[i+j>=n?i+j-n:i+j]=P[j];
		P+=Q;
	}
	bool flag=0;int m=0;for(int i=1;i<=len;++i)m=(10LL*m+v[i])%(mod-1),flag|=v[i];
	if(flag)m+=mod-1;
	P=ksm(P,m);int ans=0;
	for(int i=0;i<n;++i)if(T[i])add(ans,1LL*T[i]*P[(r-i+n)%n]%mod);
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 4024kb

input:

3 2
5

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

1 0
20

output:

1048576

result:

ok single line: '1048576'

Test #3:

score: 0
Accepted
time: 3ms
memory: 4108kb

input:

10 8
97441781169999

output:

39483594

result:

ok single line: '39483594'

Test #4:

score: 0
Accepted
time: 3ms
memory: 4168kb

input:

10 0
73529553919999

output:

913188246

result:

ok single line: '913188246'

Test #5:

score: 0
Accepted
time: 3ms
memory: 3968kb

input:

10 5
7216893652

output:

803006513

result:

ok single line: '803006513'

Test #6:

score: 0
Accepted
time: 3ms
memory: 4000kb

input:

51 4
490466735660935366104362911237439817660296497884511278059120667639249811034386376211440059814876153833104198879999

output:

754741857

result:

ok single line: '754741857'

Test #7:

score: 0
Accepted
time: 3ms
memory: 3968kb

input:

45 0
6216871967465786523158710331777577058507955388049665933617608862925909208090781993189722633093256714163855609550090284484136100755698161980229368887021285893611742334609577808667250730098679567168835635687562524497440298178123243152474212724715349775392879081815671155873083166544656572426801376...

output:

247716490

result:

ok single line: '247716490'

Test #8:

score: 0
Accepted
time: 3ms
memory: 4132kb

input:

123 95
82762777129999

output:

104574851

result:

ok single line: '104574851'

Test #9:

score: 0
Accepted
time: 3ms
memory: 4124kb

input:

100 8
31437474627210849758566270683758273881261075882083602376365854183768172131884521374556483688326470349999

output:

204425046

result:

ok single line: '204425046'

Test #10:

score: 0
Accepted
time: 1ms
memory: 4008kb

input:

101 65
129135732687243444162224693341284265097302999818949156642879266983062901971745283891629743024085567839999

output:

902554661

result:

ok single line: '902554661'

Test #11:

score: 0
Accepted
time: 1ms
memory: 4180kb

input:

102 0
3488151969475412325389878205822308160017247852281650623347454005909349359794006198664575307015721114499999

output:

162486241

result:

ok single line: '162486241'

Test #12:

score: 0
Accepted
time: 8ms
memory: 3980kb

input:

1012 291
7646813626

output:

980146392

result:

ok single line: '980146392'

Test #13:

score: 0
Accepted
time: 3ms
memory: 4072kb

input:

10 1
8252321334895940615769970904772140913784950414733677250236907211278760730743749190165425246198980003063223759998857676592610546612494049860039116369420896260329913339201912705127782100719073680933781912596330763621573961781964610789874205137283507240907978239171437180129623254976853141357534721...

output:

652741132

result:

ok single line: '652741132'

Test #14:

score: 0
Accepted
time: 248ms
memory: 5148kb

input:

10000 7418
3245239614838766441165109131458206859599048822364196500920217765340625035454604743711500986644932444050563968810069079688108908878846571710567968402401812796927116289077099295526340820005662199516680283500266534222567954309211983031474586099314642398538154929871106845369013158161741156285...

output:

698356153

result:

ok single line: '698356153'

Test #15:

score: 0
Accepted
time: 237ms
memory: 5356kb

input:

9999 779
358336376636226042717427621455961243958393374012413730691317569180699582766828947496902145881339115917085532012414592514320100982450700615324388139090946345231102734023340224881463299658303159811283914016535239877151817544726113079790779414960958512664223829472539894897355539363031791406089...

output:

837883243

result:

ok single line: '837883243'

Test #16:

score: 0
Accepted
time: 246ms
memory: 5244kb

input:

10000 0
5959081123960981456052979042226085365217802503520521998482870583390422819313350263042136451463933153462392827184151729621677652847629006369849703956071611814775739516186470151700231702587051465357283648453972097435393937208562095551505345722276019216674741689533178156201652677931133018670075...

output:

924699691

result:

ok single line: '924699691'

Test #17:

score: 0
Accepted
time: 244ms
memory: 5352kb

input:

10000 9535
4529914918413777622528043117043450937202591529390096894597801955131392043838551780190373994052685563959267673748578051484778843491690348530040553041327206108222053240121197654468570203072462947279505179444683716795754611201162765280673498257918169149948361212426058346508829709396950512100...

output:

984036477

result:

ok single line: '984036477'

Test #18:

score: 0
Accepted
time: 214ms
memory: 5240kb

input:

9240 4639
27361723410151521150732754757747824591816341408004277395827380018571695767504374102641417978743103148415278527868597085535196798439563729486914117045504466181228391680543038904853912910914033179148538533773830859471039264891096812737067663728830538925263207278489348217296058385024096176645...

output:

918206285

result:

ok single line: '918206285'

Test #19:

score: 0
Accepted
time: 210ms
memory: 5352kb

input:

8640 0
36542487284167251663740647042989590271004990959161565599035618320359555884164889579638216196822119364835481192513876617252278990351166475479529866772377957875189299536492571051813538976297743058308068985113568320877021600430398281676260145773030952556440352937340499556103082922663344786146031...

output:

183559339

result:

ok single line: '183559339'

Test #20:

score: 0
Accepted
time: 197ms
memory: 5272kb

input:

8400 300
288271854704449002303660023988228953095431900267967796390634942331317772470120001601892932430552455756800781384921666042619127984502628855577098517482540354318793004328371417736520135839821219973136389836602550635594752488595369449820630558647394225301132623150116886896899160930010237898661...

output:

236192822

result:

ok single line: '236192822'

Test #21:

score: 0
Accepted
time: 231ms
memory: 5216kb

input:

9900 7932
60696943972373113723790595629126483514286522739943462090310067978198194825062752363577899690215576140733032790987877947244269329280647842553127506268616051081441746603578834885861401552062986268589398127724619814495854782291653679848340686262859158150894989658137076297136845970234357040248...

output:

957197274

result:

ok single line: '957197274'

Test #22:

score: 0
Accepted
time: 146ms
memory: 4952kb

input:

8064 0
47334321587030653743112677374440705129805126456129176300634909485205142778452960069919888488272962888344558362309553430584472473664877747506095230385831376281275441466113307422446138481496975295148631099507964104577181484367166622611546731949305572711810831571898086598100505274361166695152297...

output:

669865153

result:

ok single line: '669865153'

Test #23:

score: 0
Accepted
time: 128ms
memory: 5052kb

input:

7560 4251
33923778033803241908219943724011782970171842843279830346925914273149746589031596306410354155061775627084155077246765927736846008968413480151788681683200760666695266835650540805104008248152259180695495822884752048464024168111056913040542477162151971025210582160878305329922703362973968810986...

output:

416930414

result:

ok single line: '416930414'

Test #24:

score: 0
Accepted
time: 0ms
memory: 4024kb

input:

1 0
1

output:

2

result:

ok single line: '2'

Test #25:

score: 0
Accepted
time: 3ms
memory: 4076kb

input:

20 0
1

output:

2

result:

ok single line: '2'

Test #26:

score: 0
Accepted
time: 3ms
memory: 4032kb

input:

20 13
1

output:

0

result:

ok single line: '0'

Test #27:

score: 0
Accepted
time: 266ms
memory: 5148kb

input:

10000 4469
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

290641673

result:

ok single line: '290641673'

Test #28:

score: 0
Accepted
time: 131ms
memory: 4972kb

input:

7560 4041
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

74525042

result:

ok single line: '74525042'

Test #29:

score: 0
Accepted
time: 245ms
memory: 5160kb

input:

9973 5944
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

881015534

result:

ok single line: '881015534'

Test #30:

score: 0
Accepted
time: 212ms
memory: 5412kb

input:

9240 105
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

971384312

result:

ok single line: '971384312'

Test #31:

score: 0
Accepted
time: 137ms
memory: 4216kb

input:

9240 407
3576

output:

801993513

result:

ok single line: '801993513'

Test #32:

score: 0
Accepted
time: 204ms
memory: 5356kb

input:

9240 551
204209679712117827730880226353510653024223856012233043639816521107053027427255530900909664190550923070609753205194078932813278453978969048551211039657884854091997550079122709572652601873661760656527148885540570009859983720628938737170862051434146563351143193685385454224852792784922646291244...

output:

119770088

result:

ok single line: '119770088'

Test #33:

score: 0
Accepted
time: 202ms
memory: 5340kb

input:

9192 1641
28752004253121823698377995642551444541478381100254351866855183106035619529957426500407613584351534638072131717174182778385021012676126168908318080221306891576946788376768991282644482141901027923976862288282903183550700780004336592004853856682722677717408026522325784466832796601495789309612...

output:

634482984

result:

ok single line: '634482984'

Test #34:

score: 0
Accepted
time: 129ms
memory: 4164kb

input:

9108 417
2572

output:

585665409

result:

ok single line: '585665409'