QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#339267#4064. 数位ushg8877100 ✓4663ms15064kbC++143.1kb2024-02-26 22:12:072024-02-26 22:12:07

Judging History

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

  • [2024-02-26 22:12:07]
  • 评测
  • 测评结果:100
  • 用时:4663ms
  • 内存:15064kb
  • [2024-02-26 22:12:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1005;
const int MR=55;
const int MOD=998244353;
ll pw[11][MAXN*MR],fac[MR],inf[MR],c[MR][MR];
struct Big_Int{
int a[MAXN+5];
int& operator [](int x){return a[x];}
Big_Int(int x=0){
	memset(a,0,sizeof(a));
	for(int i=0;i<=10;i++) a[i]=x%10,x/=10;
}
}L,R;int k;
Big_Int read(){
	Big_Int re;int n=0;char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	while(ch>='0'&&ch<='9') re[n++]=ch-'0',ch=getchar();
	reverse(re.a,re.a+n);
	return re;
}
Big_Int operator +(Big_Int x,Big_Int y){
	for(int i=0;i<MAXN;i++){
		x[i]+=y[i];
		if(x[i]>=10) x[i]-=10,x[i+1]++;
	}
	return x;
}
Big_Int operator -(Big_Int x,Big_Int y){
	for(int i=0;i<MAXN;i++){
		x[i]-=y[i];
		if(x[i]<0) x[i]+=10,x[i+1]--;
	}
	return x;
}
bool operator >=(Big_Int x,Big_Int y){
	for(int i=MAXN;i>=0;i--) if(x[i]!=y[i]) return x[i]>y[i];
	return true;
}
Big_Int operator *(Big_Int x,int y){
	for(int i=0;i<MAXN;i++) x[i]*=y;
	for(int i=0;i<MAXN;i++) x[i+1]+=x[i]/10,x[i]%=10;
	return x;
}
int operator %(Big_Int x,int y){
	int ans=0;
	for(int i=MAXN-1;i>=0;i--) ans=(10ll*ans+x[i])%y;
	return ans;
}
ll ksm(ll a,int b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;}
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int f[MR],g[MR];// all possible S, calculate the sum of S^k
ll C(int x,int y){return fac[y]*inf[x]%MOD*inf[y-x]%MOD;}
void solve(Big_Int R,int *ans){
	static int f[MAXN][10][MR][2],g[MAXN][10][MR];
	ans[0]=1;
	memset(f,0,sizeof(f));memset(g,0,sizeof(g));
	int n=MAXN;
	while(n&&!R[n]) n--;
	for(int i=n+1;i>=0;i--){
		f[i][9][0][i==n+1]++;ans[0]--;
		for(int j=0;j<=9;j++) for(int t=0;t<k;t++) if(i&&f[i][j][t][1]){
			int lim=min(j,R[i-1]);
			for(int c=0;c<=lim;c++) for(int p=0;p+t<k;p++)
				add(f[i-1][c][p+t][c==R[i-1]],
				f[i][j][t][1]*pw[10][(i-1)*p]%MOD*pw[c][p]%MOD*C(p,p+t)%MOD);
		}
		for(int c=0;c<=9;c++) for(int t=0;t<k;t++){
			for(int p=0;p<=t;p++) add(f[i][c][t][0],
				C(p,t)*g[i+1][c][t-p]%MOD*pw[10][i*p]%MOD*pw[c][p]%MOD);
		}
		for(int t=0;t<k;t++){
			g[i][9][t]=f[i][9][t][0];
			for(int c=8;c>=0;c--) g[i][c][t]=(g[i][c+1][t]+f[i][c][t][0])%MOD;
		}
	}
	for(int i=0;i<=9;i++) for(int o:{0,1}) for(int t=0;t<k;t++)
		add(ans[t],f[0][i][t][o]);
}
int main(){
	// freopen("digit.in","r",stdin);
	// freopen("digit.out","w",stdout);
	L=read();R=read();k=read()%MOD;
	for(int i=0;i<=10;i++){
		pw[i][0]=1;
		for(int j=1;j<MAXN*MR;j++) pw[i][j]=pw[i][j-1]*i%MOD;
	}
	fac[0]=inf[0]=1;
	for(int i=1;i<MR;i++) inf[i]=ksm(fac[i]=fac[i-1]*i%MOD,MOD-2);
	int ans=0;
	solve(R*k,f);
	for(int i=0;i<=k;i++)if(R*k>=(R+1)*i+L*(k-i)){
		memset(g,0,sizeof(g));
		solve(L*(k-i)+(R+Big_Int(1))*i-Big_Int(1),g);
		ll x=((L-Big_Int(1))*k+(R-L+Big_Int(1))*i+Big_Int(1))%MOD;
		c[0][0]=1;
		for(int i=1;i<=k-1;i++){
			for(int j=0;j<=i;j++) c[i][j]=((j?c[i-1][j-1]:0)+(MOD-x-(i-1))*c[i-1][j])%MOD;
		}
		int sum=0;
		for(int i=0;i<=k-1;i++) add(sum,inf[k-1]*c[k-1][i]%MOD*(f[i]-g[i]+MOD)%MOD);
		add(ans,fac[k]*inf[i]%MOD*inf[k-i]%MOD*(i&1?MOD-1:1)%MOD*sum%MOD);	
	}
	cout<<ans<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3392
46912
1

output:

805

result:

ok single line: '805'

Test #2:

score: 4
Accepted
time: 7ms
memory: 14916kb

input:

13532
47266
10

output:

122959566

result:

ok single line: '122959566'

Test #3:

score: 4
Accepted
time: 12ms
memory: 14996kb

input:

15214
22278
20

output:

608248568

result:

ok single line: '608248568'

Test #4:

score: 4
Accepted
time: 13ms
memory: 14996kb

input:

6
99003
30

output:

482049151

result:

ok single line: '482049151'

Test #5:

score: 4
Accepted
time: 51ms
memory: 15064kb

input:

9
80769
50

output:

216492918

result:

ok single line: '216492918'

Test #6:

score: 4
Accepted
time: 8ms
memory: 15028kb

input:

1661415752712512
5964898077730636
10

output:

936625623

result:

ok single line: '936625623'

Test #7:

score: 4
Accepted
time: 8ms
memory: 14896kb

input:

1200579546507207
2780466319667767
10

output:

181223761

result:

ok single line: '181223761'

Test #8:

score: 4
Accepted
time: 9ms
memory: 14968kb

input:

1777841640199213
3258697463679490
20

output:

56613960

result:

ok single line: '56613960'

Test #9:

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

input:

4396068490813531
6104232936024870
30

output:

0

result:

ok single line: '0'

Test #10:

score: 4
Accepted
time: 101ms
memory: 15040kb

input:

16704
9927325292555697
50

output:

40597371

result:

ok single line: '40597371'

Test #11:

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

input:

90277591632981005637511891419553335008894215272
7151128610726280410864354374074497009953207950969
2

output:

698075340

result:

ok single line: '698075340'

Test #12:

score: 4
Accepted
time: 9ms
memory: 15056kb

input:

9477832587309291983340387546272743455167798613
1245715737463737313784854721100496317180360749290
10

output:

162942864

result:

ok single line: '162942864'

Test #13:

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

input:

344549471727489537610822623142934344796179924114613214695586176283275658977506126477184
969554227207884436922056771032600678937706198645623688000238210627413041301376963393077762280632554
2

output:

961546592

result:

ok single line: '961546592'

Test #14:

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

input:

55350509444556236446489457193605524917606412551996706958914890427820
796633666119509733722829652894763207010933659369167574477416331616753023016195847061482606535760353
3

output:

397248010

result:

ok single line: '397248010'

Test #15:

score: 4
Accepted
time: 8ms
memory: 14960kb

input:

138251241998583033991903059942269415823959009536421286667258656732346100589418242462412182985595442
339919849080126654459066794007676689386443370060788033742828108084237457545776545503179913636573448
10

output:

490872962

result:

ok single line: '490872962'

Test #16:

score: 4
Accepted
time: 6ms
memory: 14980kb

input:

927685205033
5575536794982905806425239990181295597257250491679740441581830071525048803618361049491471087844784966092904923890699550851039804070930668638933439325066713794313510011632557255258734207703758205116560
3

output:

181409096

result:

ok single line: '181409096'

Test #17:

score: 4
Accepted
time: 13ms
memory: 14968kb

input:

999569029973884755522795328733368112701348002412014586524980987651729105371176117825904775046301128496282074900254576434321396687405471037392275646394389957155
49393920830259762616940813985547280476949470893658354774636263855848574111237652505416643006097489537167480334086006837361271286305913947797...

output:

702502233

result:

ok single line: '702502233'

Test #18:

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

input:

8540840719139702289624790878247741981564159768603249001614258402171061066624257393702969028823865341113180421296914121333005108958790526773803098324001402111775984503375201804466808904069942757613152652915985666815559894900047034786298234767440923006333478
5755814463185413341244886153840162411268212...

output:

276677763

result:

ok single line: '276677763'

Test #19:

score: 4
Accepted
time: 14ms
memory: 14960kb

input:

4592572524766435916679222618738837049416894166053936895395505912960526507177233771043086690771099275174800794066982280394148031787941300813966995625296415838677651245593193131241422420580434739398657652566305582300249242054203622475682953956814446479923856986575382208157521440213688872793
3167046349...

output:

677937038

result:

ok single line: '677937038'

Test #20:

score: 4
Accepted
time: 103ms
memory: 14968kb

input:

5898816329482189046579078953503480776749598982266875508818427728825444183245110497323545852497668081389765954149072577903205251532234533068434666170086759184744071894408172002010950054326919213467664796456001726377624972619008916368790429445799644337206714697033315020479072988802192631326
3908936160...

output:

497869023

result:

ok single line: '497869023'

Test #21:

score: 4
Accepted
time: 27ms
memory: 14964kb

input:

416077135638317445536943867628542913052302934955640979356188973157589460344101136852730724985718368477325961186386856456820487785898764746554458199915929556462027164812506567366986435575266469646656045545361554974712299613777621011165556685609748945707932215438082820583574624798718852124775398348916...

output:

148524071

result:

ok single line: '148524071'

Test #22:

score: 4
Accepted
time: 167ms
memory: 14976kb

input:

295826594914760304325907309934549158421387322296161141878089722717427179715455470814923006074231600118320692610400298841949944432204702490787104302799797853612986674970446486667294428879359091974427817224968674631416076953231368
36310609856600413922296328635208035277798081477841392427515969406353329...

output:

237151087

result:

ok single line: '237151087'

Test #23:

score: 4
Accepted
time: 1043ms
memory: 14972kb

input:

381953364943939098902524953044328524168408632851913776188216901954517439038492667203820226478068621390897046782873629043791900541549306236673442157838603512468035618581682653840726911713269176012731482830013667977227042972776810686877451449181911604023475608546148703168105794003631353879536113541015...

output:

851817319

result:

ok single line: '851817319'

Test #24:

score: 4
Accepted
time: 4663ms
memory: 14928kb

input:

221023242555605899900491008196492231074996838791376676416505250708428133985961719817170395921283156815859622871496409152323312423080394045262737049242076015662416159078412501135147834250684751265051793836549465577791390688041874385541001362905309176109389407929581342753081530034330083207737699687155...

output:

330824991

result:

ok single line: '330824991'

Test #25:

score: 4
Accepted
time: 4586ms
memory: 14932kb

input:

72515968946069616137331569198803027671625997413892339448066260495238126267822345884881140842795833095368403765972532276506951555130898786623069616794
210332671198602929306963624682411927128766482093191016379462700590170137088740959831354360319659063897359912121098422514099790138088919941883046490370...

output:

57981270

result:

ok single line: '57981270'

Extra Test:

score: 0
Extra Test Passed