QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412023#8347. 毒假强zhouhuanyi100 ✓388ms11404kbC++143.0kb2024-05-15 23:14:482024-05-15 23:14:49

Judging History

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

  • [2024-05-15 23:14:49]
  • 评测
  • 测评结果:100
  • 用时:388ms
  • 内存:11404kb
  • [2024-05-15 23:14:48]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define K 20
#define N 26
#define M 1000000
using namespace std;
long long read()
{
    char c=0;
    long long sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
__int128 sk,n,op[K+1],c[K+1],dp[K+1][10],DP[K+1][2],dps[N+1][M+1][2],st,d[2],e[2],rst,ans;
void Adder(__int128 &x,__int128 d)
{
    x+=d;
    if (x>=n) x=n;
    return;
}
void dfs(int x)
{
    if (x==K+1)
    {
	for (int i=K-sk;i<=K;++i) DP[i][0]=DP[i][1]=0;
	DP[K-sk][op[K]]=1;
	for (int i=K-sk+1;i<=K;++i)
	    for (int op=0,opt;op<=1;++op)
		for (int j=0,k;j<=9;++j)
		{
		    k=j-op;
		    if (k<0) k+=10,opt=1;
		    else opt=0;
		    if (k!=9) Adder(DP[i][opt],DP[i-1][op]*dp[i][j]);
		}
	Adder(rst,DP[K][0]);
	return;
    }
    __int128 res;
    bool opt;
    for (int i=0;i<=1;++i)
    {
	op[x]=i,opt=0;
	if (x-sk>=1)
	{
	    for (int j=0;j<=9;++j) dp[x][j]=(c[x]==-1)||(c[x]==j);
	    for (int j=0,t,opts;j<=9;++j)
	    {
		res=0;
		for (int k=0;k<=9;++k)
		{
		    t=k-j-op[x-1];
		    if (t<0) t+=10,opts=1;
		    else opts=0;
		    if (opts==i&&t!=9) Adder(res,dp[x-sk][k]);
		}
		dp[x][j]=min(dp[x][j]*res,n);
	    }
	}
	else
	{
	    for (int j=0;j<=9;++j) dp[x][j]=(c[x]==-1)||(c[x]==j);
	    for (int j=0,k,opts;j<=9;++j)
	    {
		k=-j-op[x-1];
		if (k<0) k+=10,opts=1;
		else opts=0;
		if (opts!=i||k==9) dp[x][j]=0;
	    }
	}
	for (int j=0;j<=9;++j) opt|=(dp[x][j]>0);
	if (opt) dfs(x+1);
    }
    return;
}
__int128 solve()
{
    rst=0,dfs(1);
    return rst;
}
void write(__int128 x)
{
    if (!x) return;
    write(x/10),printf("%d",(int)(x%10));
    return;
}
int main()
{
    __int128 res,dst,S=1;
    sk=read(),n=read()+1,res=n;
    if (sk<=5)
    {
	S=1;
	for (int i=1;i<=sk;++i) S*=10;
	dps[0][0][0]=1;
	for (int i=1;i<=N;++i)
	    for (int j=0,k;j<S;++j)
		for (int op=0,opt;op<=1;++op)
		    if (dps[i-1][j][op])
			for (int t=0;t<=9;++t)
			{
			    k=j/(S/10)-t-op;
			    if (k<0) k+=10,opt=1;
			    else opt=0;
			    if (k!=9) Adder(dps[i][(j*10+t)%S][opt],dps[i-1][j][op]);
			}
	st=0,d[0]=1,d[1]=0,res=n;
	for (int i=N;i>=1;--i)
	{
	    for (int j=0,k;j<=9;++j)
	    {
		rst=0;
		for (int op=0,opt;op<=1;++op)
		{
		    k=j-st%10-op;
		    if (k<0) k+=10,opt=1;
		    else opt=0;
		    if (k!=9) Adder(rst,d[opt]*dps[i-1][st/10+j*(S/10)][op]);
		}
		if (res<=rst)
		{
		    e[0]=e[1]=0;
		    for (int op=0,opt;op<=1;++op)
		    {
			k=j-st%10-op;
			if (k<0) k+=10,opt=1;
			else opt=0;
		        if (k!=9) Adder(e[op],d[opt]);
		    }
		    st=st/10+j*(S/10);
		    if (i>sk) ans=ans*10+j;
		    d[0]=e[0],d[1]=e[1];
		    break;
		}
		res-=rst;
	    }
	}
	write(ans),puts("");
    }
    else
    {
	for (int i=1;i<=K;++i) c[i]=-1;
	for (int i=K;i>=1;--i)
	    for (int j=0;j<=9;++j)
	    {
		c[i]=j,dst=solve();
		if (res<=dst) break;
		else res-=dst;
	    }
	for (int i=K;i>=1;--i) ans=ans*10+c[i];
	write(ans),puts("");
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 25
Accepted

Test #1:

score: 25
Accepted
time: 1ms
memory: 4284kb

input:

2 653

output:

1069

result:

ok single line: '1069'

Test #2:

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

input:

2 729

output:

1168

result:

ok single line: '1168'

Test #3:

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

input:

2 378

output:

569

result:

ok single line: '569'

Test #4:

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

input:

3 673

output:

1329

result:

ok single line: '1329'

Test #5:

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

input:

3 803

output:

1514

result:

ok single line: '1514'

Test #6:

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

input:

3 999

output:

1772

result:

ok single line: '1772'

Test #7:

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

input:

1 754

output:

1142

result:

ok single line: '1142'

Test #8:

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

input:

3 673

output:

1329

result:

ok single line: '1329'

Test #9:

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

input:

3 728

output:

1390

result:

ok single line: '1390'

Test #10:

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

input:

3 644

output:

1277

result:

ok single line: '1277'

Test #11:

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

input:

3 403

output:

734

result:

ok single line: '734'

Test #12:

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

input:

2 196

output:

286

result:

ok single line: '286'

Test #13:

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

input:

1 73

output:

90

result:

ok single line: '90'

Test #14:

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

input:

2 661

output:

1079

result:

ok single line: '1079'

Test #15:

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

input:

1 648

output:

889

result:

ok single line: '889'

Subtask #2:

score: 35
Accepted

Test #16:

score: 35
Accepted
time: 1ms
memory: 4124kb

input:

1 345034715579071096

output:

2513029422339367072

result:

ok single line: '2513029422339367072'

Test #17:

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

input:

1 928064447724082316

output:

6841649390539291284

result:

ok single line: '6841649390539291284'

Test #18:

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

input:

1 541392330132197148

output:

3934945708734153715

result:

ok single line: '3934945708734153715'

Test #19:

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

input:

1 932096632324717020

output:

6866796948572468426

result:

ok single line: '6866796948572468426'

Test #20:

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

input:

1 114451898294099023

output:

751984975176342275

result:

ok single line: '751984975176342275'

Test #21:

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

input:

1 235498410350575794

output:

1678575115834518445

result:

ok single line: '1678575115834518445'

Test #22:

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

input:

1 263087596959546780

output:

1854129753611416834

result:

ok single line: '1854129753611416834'

Test #23:

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

input:

1 576677905677423798

output:

4168653345619750896

result:

ok single line: '4168653345619750896'

Test #24:

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

input:

1 715338160945566811

output:

5200349120580131175

result:

ok single line: '5200349120580131175'

Test #25:

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

input:

1 732471942288061103

output:

5313900915618634928

result:

ok single line: '5313900915618634928'

Test #26:

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

input:

1 81591921669173834

output:

533613350411224447

result:

ok single line: '533613350411224447'

Test #27:

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

input:

1 444041620832982561

output:

3172902012381803952

result:

ok single line: '3172902012381803952'

Test #28:

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

input:

1 6697181292380282

output:

39407408296042592

result:

ok single line: '39407408296042592'

Test #29:

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

input:

1 952035664236484391

output:

7007633864782456009

result:

ok single line: '7007633864782456009'

Test #30:

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

input:

1 119337166106580019

output:

792828609748126894

result:

ok single line: '792828609748126894'

Subtask #3:

score: 40
Accepted

Test #31:

score: 40
Accepted
time: 15ms
memory: 3776kb

input:

12 874620678069272691

output:

22463825142185819370

result:

ok single line: '22463825142185819370'

Test #32:

score: 0
Accepted
time: 2ms
memory: 3800kb

input:

16 802614516796786027

output:

35407415665622422294

result:

ok single line: '35407415665622422294'

Test #33:

score: 0
Accepted
time: 310ms
memory: 3764kb

input:

6 756647802834648987

output:

10438847716008292465

result:

ok single line: '10438847716008292465'

Test #34:

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

input:

3 226896403387130337

output:

2059211761939710776

result:

ok single line: '2059211761939710776'

Test #35:

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

input:

1 347488145421093192

output:

2527387074818969159

result:

ok single line: '2527387074818969159'

Test #36:

score: 0
Accepted
time: 5ms
memory: 3792kb

input:

14 193000621330864201

output:

6067357863414375200

result:

ok single line: '6067357863414375200'

Test #37:

score: 0
Accepted
time: 388ms
memory: 3772kb

input:

6 954115818600650251

output:

12864634150158375562

result:

ok single line: '12864634150158375562'

Test #38:

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

input:

17 743225133605738266

output:

37311263433846176756

result:

ok single line: '37311263433846176756'

Test #39:

score: 0
Accepted
time: 32ms
memory: 3780kb

input:

9 252020961388627232

output:

4250078145252196572

result:

ok single line: '4250078145252196572'

Test #40:

score: 0
Accepted
time: 14ms
memory: 4068kb

input:

12 625490241962472026

output:

15466218565422592895

result:

ok single line: '15466218565422592895'

Test #41:

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

input:

17 954452527346520859

output:

48142667151713611623

result:

ok single line: '48142667151713611623'

Test #42:

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

input:

3 976431687783080972

output:

8829664277323469345

result:

ok single line: '8829664277323469345'

Test #43:

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

input:

1 847601466910992894

output:

6192959617472541715

result:

ok single line: '6192959617472541715'

Test #44:

score: 0
Accepted
time: 16ms
memory: 11404kb

input:

4 151280662907406040

output:

1473815899034367653

result:

ok single line: '1473815899034367653'

Test #45:

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

input:

2 888548487913703829

output:

7283410115572769456

result:

ok single line: '7283410115572769456'