QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345148#4064. 数位Lynkcat100 ✓772ms13020kbC++204.9kb2024-03-06 11:09:142024-03-06 11:09:15

Judging History

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

  • [2024-03-06 11:09:15]
  • 评测
  • 测评结果:100
  • 用时:772ms
  • 内存:13020kb
  • [2024-03-06 11:09:14]
  • 提交

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) ((int)((x).size()))
#define int ll
// #define N 
using namespace std;
string L,R;
int l,r;
int n;
int C[3005][3005];
inline ll quickPower(ll x,ll y)
{
	ll res=1;
	while (y)
	{
		if (y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
inline int md(string x)
{
	int res=0;
	for (auto u:x) res=(res*10+u-'0')%mod;
	return res;
}
inline int Cc(int x,int y)
{
	int res=1;
	for (int i=1;i<=y;i++) res=res*i%mod;
	res=quickPower(res,mod-2);
	for (int i=x;i>x-y;i--)
		res=res*i%mod;
	return res;
}
inline int F(int x,int i)
{
	int res=0;
	{
		int coef=1;
		if (i&1) coef=mod-1;
		coef=coef*C[n][i]%mod;
		coef=coef*Cc((x-l*(n-i)%mod-(r+1)*i%mod+n-1+mod+mod)%mod,n-1)%mod;
		res=(res+coef)%mod;
	}
	return res;
}
inline poly mul(poly &x,poly &y)
{
	poly res(x.size()+y.size()-1,0);
	for (int i=0;i<x.size();i++)
		for (int j=0;j<y.size();j++)
			res[i+j]=(res[i+j]+x[i]*y[j]%mod)%mod;
	return res;
}
inline poly add(poly &x,poly &y)
{
	poly res(max(x.size(),y.size()),0);
	for (int i=0;i<res.size();i++)
	{
		if (i<x.size()) res[i]=(res[i]+x[i])%mod;
		if (i<y.size()) res[i]=(res[i]+y[i])%mod;
	}
	return res;
}
inline poly div(poly &x,poly &y)
{
	poly nw=x;
	poly res(x.size()+1-y.size(),0);
	for (int i=x.size()-y.size();i>=0;i--)
	{
		res[i]=nw[i+y.size()-1]*quickPower(y.back(),mod-2)%mod;
		for (int j=y.size()-1;j>=0;j--)
		{
			nw[i+j]=(nw[i+j]-res[i]*y[j]%mod+mod)%mod;
		}
	}
	return res;
}	
inline poly cz(poly &a,poly &b)
{
	poly res(1,0);
	poly nw(1,1);
	for (int i=0;i<a.size();i++)
	{
		poly now(2,0);
		now[1]=1,now[0]=(mod-a[i])%mod;
		nw=mul(nw,now);
	}
	for (int i=0;i<a.size();i++)
	{
		poly now(2,0);
		now[1]=1,now[0]=(mod-a[i])%mod;
		nw=div(nw,now);
		int o=1;
		for (int j=0;j<a.size();j++)
			if (j!=i)
			{
				o=o*(a[i]-a[j]+mod)%mod;
			}
		o=quickPower(o,mod-2);
		o=o*b[i]%mod;
		if (o)
		{
			for (auto &u:nw) u=u*o%mod;
			res=add(res,nw);
			o=quickPower(o,mod-2);
			for (auto &u:nw) u=u*o%mod;
		}
		nw=mul(nw,now);
	}
	while (res.size()&&res.back()==0) res.pop_back();
	return res;
}
int vis[3005][11][2],DFN;
poly dp[3005][11][2];
poly all;
poly bL,bR;
int pw[3005];
inline poly dfs(int x,int lst,int y)
{
	if (x==-1)
	{
		poly g(n+1,0);
		g[0]=1;
		return g;
	}
	if (vis[x][lst][y]==DFN||!y&&vis[x][lst][y]) return dp[x][lst][y];
	vis[x][lst][y]=DFN;
	poly res(n+1,0);
	for (int i=min(9ll,lst);i>=0;i--)
	{
		if (y&&i>all[x]) continue;
		poly g=dfs(x-1,((lst!=10||lst==10&&i)?i:lst),y&(i==all[x]));
		for (int j=0;j<=n;j++)
			for (int k=0,c=1;j+k<=n;k++,c=c*pw[x]%mod*i%mod)
				res[j+k]=(res[j+k]+g[j]*c%mod*C[j+k][j]%mod)%mod;
	}
	dp[x][lst][y]=res;
	return res;
}
inline poly calc(poly &x)
{
	++DFN;
	all=x;
	pw[0]=1;
	for (int i=1;i<=sz(all);i++) pw[i]=pw[i-1]*10%mod;
	return dfs(sz(all)-1,10,1);
}
inline poly mul(poly g,int n)
{
	poly res(g.size()+10,0);
	int x=0;
	for (int i=0;i<res.size();i++)
	{
		if (i<sz(g))
			x+=g[i]*n;
		res[i]=x%10,x/=10;
	}
	while (res.size()>1&&res.back()==0) res.pop_back();
	return res;
}
inline poly add1(poly x,poly y)
{
	poly res(max(x.size(),y.size())+5,0);
	for (int i=0;i+1<res.size();i++)
	{
		if (i<sz(x)) res[i]=(res[i]+x[i]);
		if (i<sz(y)) res[i]=(res[i]+y[i]);
		res[i+1]+=res[i]/10;
		res[i]%=10;
	}
	while (res.size()>1&&res.back()==0) res.pop_back();
	return res;
}
void BellaKira()
{
	cin>>L>>R;
	for (auto u:R) bR.push_back(u-'0');
	reverse(bR.begin(),bR.end());
	for (auto u:L) bL.push_back(u-'0');
	reverse(bL.begin(),bL.end());
	cin>>n;
	C[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	l=md(L);
	r=md(R);
	int ans=0;
	bR.push_back(0);
	for (int i=0;i<sz(bR);i++)
		if (bR[i]!=9)
		{
			bR[i]++;
			for (int j=0;j<i;j++) bR[j]=0;
			break;
		}
	poly Lim=mul(bR,n);
	poly g=calc(Lim);
	for (int i=0;i<=n;i++)
	{
		poly bd=add1(mul(bL,(n-i)),mul(bR,i));
		for (int j=0;j<bd.size();j++)
			if (bd[j])
			{
				bd[j]--;
				for (int k=0;k<j;k++) bd[k]=9;
				break;
			}
		poly gg=calc(bd);
		// cerr<<i<<endl;
		for (int j=0;j<=n;j++) g[j]=(g[j]-gg[j]+mod)%mod;
		poly gx,gy;
		for (int j=12311;;j++)
		{
			if (gx.size()==100) break;
			gx.push_back(j);
			gy.push_back(F(j,i));
		}
		poly coef=cz(gx,gy);
		for (int j=0;j<sz(coef)&&j<=n;j++)
			ans=(ans+coef[j]*g[j]%mod)%mod;
		for (int j=0;j<=n;j++) g[j]=(g[j]+gg[j])%mod;
	}

	cout<<ans<<'\n';
}
signed main()
{
	// freopen("1.in","r",stdin);
	IOS;
	cin.tie(0);
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}
/*list:
1.mod 998244353 or 1e9+7 or ???
2.N
3.duipai shuju xingtai duoyidian
...
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4
Accepted
time: 4ms
memory: 5944kb

input:

3392
46912
1

output:

805

result:

ok single line: '805'

Test #2:

score: 4
Accepted
time: 16ms
memory: 5964kb

input:

13532
47266
10

output:

122959566

result:

ok single line: '122959566'

Test #3:

score: 4
Accepted
time: 30ms
memory: 7972kb

input:

15214
22278
20

output:

608248568

result:

ok single line: '608248568'

Test #4:

score: 4
Accepted
time: 45ms
memory: 7692kb

input:

6
99003
30

output:

482049151

result:

ok single line: '482049151'

Test #5:

score: 4
Accepted
time: 75ms
memory: 7980kb

input:

9
80769
50

output:

216492918

result:

ok single line: '216492918'

Test #6:

score: 4
Accepted
time: 16ms
memory: 5992kb

input:

1661415752712512
5964898077730636
10

output:

936625623

result:

ok single line: '936625623'

Test #7:

score: 4
Accepted
time: 16ms
memory: 5696kb

input:

1200579546507207
2780466319667767
10

output:

181223761

result:

ok single line: '181223761'

Test #8:

score: 4
Accepted
time: 32ms
memory: 7876kb

input:

1777841640199213
3258697463679490
20

output:

56613960

result:

ok single line: '56613960'

Test #9:

score: 4
Accepted
time: 47ms
memory: 5756kb

input:

4396068490813531
6104232936024870
30

output:

0

result:

ok single line: '0'

Test #10:

score: 4
Accepted
time: 79ms
memory: 7900kb

input:

16704
9927325292555697
50

output:

40597371

result:

ok single line: '40597371'

Test #11:

score: 4
Accepted
time: 5ms
memory: 5960kb

input:

90277591632981005637511891419553335008894215272
7151128610726280410864354374074497009953207950969
2

output:

698075340

result:

ok single line: '698075340'

Test #12:

score: 4
Accepted
time: 17ms
memory: 5748kb

input:

9477832587309291983340387546272743455167798613
1245715737463737313784854721100496317180360749290
10

output:

162942864

result:

ok single line: '162942864'

Test #13:

score: 4
Accepted
time: 2ms
memory: 5840kb

input:

344549471727489537610822623142934344796179924114613214695586176283275658977506126477184
969554227207884436922056771032600678937706198645623688000238210627413041301376963393077762280632554
2

output:

961546592

result:

ok single line: '961546592'

Test #14:

score: 4
Accepted
time: 3ms
memory: 5776kb

input:

55350509444556236446489457193605524917606412551996706958914890427820
796633666119509733722829652894763207010933659369167574477416331616753023016195847061482606535760353
3

output:

397248010

result:

ok single line: '397248010'

Test #15:

score: 4
Accepted
time: 19ms
memory: 6028kb

input:

138251241998583033991903059942269415823959009536421286667258656732346100589418242462412182985595442
339919849080126654459066794007676689386443370060788033742828108084237457545776545503179913636573448
10

output:

490872962

result:

ok single line: '490872962'

Test #16:

score: 4
Accepted
time: 3ms
memory: 6184kb

input:

927685205033
5575536794982905806425239990181295597257250491679740441581830071525048803618361049491471087844784966092904923890699550851039804070930668638933439325066713794313510011632557255258734207703758205116560
3

output:

181409096

result:

ok single line: '181409096'

Test #17:

score: 4
Accepted
time: 23ms
memory: 6028kb

input:

999569029973884755522795328733368112701348002412014586524980987651729105371176117825904775046301128496282074900254576434321396687405471037392275646394389957155
49393920830259762616940813985547280476949470893658354774636263855848574111237652505416643006097489537167480334086006837361271286305913947797...

output:

702502233

result:

ok single line: '702502233'

Test #18:

score: 4
Accepted
time: 26ms
memory: 6492kb

input:

8540840719139702289624790878247741981564159768603249001614258402171061066624257393702969028823865341113180421296914121333005108958790526773803098324001402111775984503375201804466808904069942757613152652915985666815559894900047034786298234767440923006333478
5755814463185413341244886153840162411268212...

output:

276677763

result:

ok single line: '276677763'

Test #19:

score: 4
Accepted
time: 26ms
memory: 6248kb

input:

4592572524766435916679222618738837049416894166053936895395505912960526507177233771043086690771099275174800794066982280394148031787941300813966995625296415838677651245593193131241422420580434739398657652566305582300249242054203622475682953956814446479923856986575382208157521440213688872793
3167046349...

output:

677937038

result:

ok single line: '677937038'

Test #20:

score: 4
Accepted
time: 62ms
memory: 6488kb

input:

5898816329482189046579078953503480776749598982266875508818427728825444183245110497323545852497668081389765954149072577903205251532234533068434666170086759184744071894408172002010950054326919213467664796456001726377624972619008916368790429445799644337206714697033315020479072988802192631326
3908936160...

output:

497869023

result:

ok single line: '497869023'

Test #21:

score: 4
Accepted
time: 33ms
memory: 6904kb

input:

416077135638317445536943867628542913052302934955640979356188973157589460344101136852730724985718368477325961186386856456820487785898764746554458199915929556462027164812506567366986435575266469646656045545361554974712299613777621011165556685609748945707932215438082820583574624798718852124775398348916...

output:

148524071

result:

ok single line: '148524071'

Test #22:

score: 4
Accepted
time: 90ms
memory: 7032kb

input:

295826594914760304325907309934549158421387322296161141878089722717427179715455470814923006074231600118320692610400298841949944432204702490787104302799797853612986674970446486667294428879359091974427817224968674631416076953231368
36310609856600413922296328635208035277798081477841392427515969406353329...

output:

237151087

result:

ok single line: '237151087'

Test #23:

score: 4
Accepted
time: 306ms
memory: 9216kb

input:

381953364943939098902524953044328524168408632851913776188216901954517439038492667203820226478068621390897046782873629043791900541549306236673442157838603512468035618581682653840726911713269176012731482830013667977227042972776810686877451449181911604023475608546148703168105794003631353879536113541015...

output:

851817319

result:

ok single line: '851817319'

Test #24:

score: 4
Accepted
time: 772ms
memory: 13020kb

input:

221023242555605899900491008196492231074996838791376676416505250708428133985961719817170395921283156815859622871496409152323312423080394045262737049242076015662416159078412501135147834250684751265051793836549465577791390688041874385541001362905309176109389407929581342753081530034330083207737699687155...

output:

330824991

result:

ok single line: '330824991'

Test #25:

score: 4
Accepted
time: 766ms
memory: 12932kb

input:

72515968946069616137331569198803027671625997413892339448066260495238126267822345884881140842795833095368403765972532276506951555130898786623069616794
210332671198602929306963624682411927128766482093191016379462700590170137088740959831354360319659063897359912121098422514099790138088919941883046490370...

output:

57981270

result:

ok single line: '57981270'

Extra Test:

score: 0
Extra Test Passed