QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269416#1875. NeinzhouhuanyiAC ✓283ms71460kbC++233.0kb2023-11-29 16:50:522023-11-29 16:50:53

Judging History

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

  • [2023-11-29 16:50:53]
  • 评测
  • 测评结果:AC
  • 用时:283ms
  • 内存:71460kb
  • [2023-11-29 16:50:52]
  • 提交

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

Test #1:

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

input:

1 1

output:

2

result:

ok answer is '2'

Test #2:

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

input:

1 8

output:

9

result:

ok answer is '9'

Test #3:

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

input:

1 9

output:

12

result:

ok answer is '12'

Test #4:

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

input:

1 10

output:

13

result:

ok answer is '13'

Test #5:

score: 0
Accepted
time: 167ms
memory: 71400kb

input:

5 1

output:

11112

result:

ok answer is '11112'

Test #6:

score: 0
Accepted
time: 171ms
memory: 71372kb

input:

5 84

output:

11235

result:

ok answer is '11235'

Test #7:

score: 0
Accepted
time: 159ms
memory: 71372kb

input:

5 668

output:

12345

result:

ok answer is '12345'

Test #8:

score: 0
Accepted
time: 173ms
memory: 71392kb

input:

5 733942

output:

2281488

result:

ok answer is '2281488'

Test #9:

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

input:

18 528599760553218747

output:

30725517742188427234

result:

ok answer is '30725517742188427234'

Test #10:

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

input:

18 964828716126767591

output:

55758681752658348563

result:

ok answer is '55758681752658348563'

Test #11:

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

input:

18 401057671700316435

output:

22687686284122211545

result:

ok answer is '22687686284122211545'

Test #12:

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

input:

18 837286627273865280

output:

48255733668453323265

result:

ok answer is '48255733668453323265'

Test #13:

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

input:

18 273515582847414124

output:

15116382182883344554

result:

ok answer is '15116382182883344554'

Test #14:

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

input:

18 55923968082999579

output:

2876461768512185545

result:

ok answer is '2876461768512185545'

Test #15:

score: 0
Accepted
time: 44ms
memory: 3748kb

input:

8 715524960511324231

output:

12022650248772112989

result:

ok answer is '12022650248772112989'

Test #16:

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

input:

16 151753916084873076

output:

6182363727541142425

result:

ok answer is '6182363727541142425'

Test #17:

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

input:

2 587982875953389216

output:

4754915500630529532

result:

ok answer is '4754915500630529532'

Test #18:

score: 0
Accepted
time: 11ms
memory: 3832kb

input:

10 24211831526938061

output:

410770411555582497

result:

ok answer is '410770411555582497'

Test #19:

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

input:

18 460440787100486905

output:

26131416714411853682

result:

ok answer is '26131416714411853682'

Test #20:

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

input:

8 896669742674035749

output:

14750223579258782248

result:

ok answer is '14750223579258782248'

Test #21:

score: 0
Accepted
time: 19ms
memory: 3840kb

input:

12 556270735102360402

output:

13827553636696643430

result:

ok answer is '13827553636696643430'

Test #22:

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

input:

2 992499694970876542

output:

8147123087598806742

result:

ok answer is '8147123087598806742'

Test #23:

score: 0
Accepted
time: 24ms
memory: 3836kb

input:

9 191349424180689911

output:

3224103375245122149

result:

ok answer is '3224103375245122149'

Test #24:

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

input:

1 1000000000000000000

output:

7317596822929805779

result:

ok answer is '7317596822929805779'

Test #25:

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

input:

2 1000000000000000000

output:

8207298656583156714

result:

ok answer is '8207298656583156714'

Test #26:

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

input:

3 1000000000000000000

output:

10124840976332612776

result:

ok answer is '10124840976332612776'

Test #27:

score: 0
Accepted
time: 18ms
memory: 11024kb

input:

4 1000000000000000000

output:

11134918859204347753

result:

ok answer is '11134918859204347753'

Test #28:

score: 0
Accepted
time: 180ms
memory: 71460kb

input:

5 1000000000000000000

output:

12248384925950595769

result:

ok answer is '12248384925950595769'

Test #29:

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

input:

6 1000000000000000000

output:

13481441167144812720

result:

ok answer is '13481441167144812720'

Test #30:

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

input:

7 1000000000000000000

output:

14851839567286627600

result:

ok answer is '14851839567286627600'

Test #31:

score: 0
Accepted
time: 61ms
memory: 3836kb

input:

8 1000000000000000000

output:

16400312227388843586

result:

ok answer is '16400312227388843586'

Test #32:

score: 0
Accepted
time: 43ms
memory: 3836kb

input:

9 1000000000000000000

output:

18070802619848417970

result:

ok answer is '18070802619848417970'

Test #33:

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

input:

10 1000000000000000000

output:

18876263506622668979

result:

ok answer is '18876263506622668979'

Test #34:

score: 0
Accepted
time: 23ms
memory: 3708kb

input:

11 1000000000000000000

output:

22516357784746378893

result:

ok answer is '22516357784746378893'

Test #35:

score: 0
Accepted
time: 10ms
memory: 3820kb

input:

12 1000000000000000000

output:

25606071173776613626

result:

ok answer is '25606071173776613626'

Test #36:

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

input:

13 1000000000000000000

output:

30153652575287329992

result:

ok answer is '30153652575287329992'

Test #37:

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

input:

14 1000000000000000000

output:

34032144146113465692

result:

ok answer is '34032144146113465692'

Test #38:

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

input:

15 1000000000000000000

output:

38476235652741893950

result:

ok answer is '38476235652741893950'

Test #39:

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

input:

16 1000000000000000000

output:

44453843638835448269

result:

ok answer is '44453843638835448269'

Test #40:

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

input:

17 1000000000000000000

output:

51178357488582512218

result:

ok answer is '51178357488582512218'

Test #41:

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

input:

18 1000000000000000000

output:

57644143667246653868

result:

ok answer is '57644143667246653868'

Test #42:

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

input:

11 169906399332236675

output:

3542071158723189134

result:

ok answer is '3542071158723189134'

Test #43:

score: 0
Accepted
time: 34ms
memory: 3812kb

input:

10 836507396055528616

output:

15844261021999264957

result:

ok answer is '15844261021999264957'

Test #44:

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

input:

18 271736347334110166

output:

14838142784382116438

result:

ok answer is '14838142784382116438'

Test #45:

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

input:

13 705965302907659012

output:

20780554485617714682

result:

ok answer is '20780554485617714682'

Test #46:

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

input:

17 141194262776175153

output:

6535463816612312328

result:

ok answer is '6535463816612312328'

Test #47:

score: 0
Accepted
time: 11ms
memory: 3744kb

input:

12 575423218349724000

output:

14318523724188758677

result:

ok answer is '14318523724188758677'

Test #48:

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

input:

11 10652178218240141

output:

201716847375538682

result:

ok answer is '201716847375538682'

Test #49:

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

input:

15 677253166351597490

output:

25718425137845667325

result:

ok answer is '25718425137845667325'

Test #50:

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

input:

14 112482121925146336

output:

3478827471866842353

result:

ok answer is '3478827471866842353'

Test #51:

score: 0
Accepted
time: 7ms
memory: 4112kb

input:

13 138182159835368774

output:

3736504553128889177

result:

ok answer is '3736504553128889177'

Test #52:

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

input:

17 572411115408917620

output:

28263577418567266116

result:

ok answer is '28263577418567266116'

Test #53:

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

input:

16 7640070982466466

output:

275752565647555878

result:

ok answer is '275752565647555878'

Test #54:

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

input:

15 441869026556015312

output:

16212131234378684940

result:

ok answer is '16212131234378684940'

Test #55:

score: 0
Accepted
time: 4ms
memory: 3844kb

input:

14 876097982129564158

output:

30138111462733879719

result:

ok answer is '30138111462733879719'

Test #56:

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

input:

18 543698978852856099

output:

31531851816668641477

result:

ok answer is '31531851816668641477'

Test #57:

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

input:

17 977927934426404945

output:

50224732558555875933

result:

ok answer is '50224732558555875933'

Test #58:

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

input:

16 413156889999953790

output:

17247527871564162333

result:

ok answer is '17247527871564162333'

Test #59:

score: 0
Accepted
time: 6ms
memory: 3840kb

input:

15 847385845573502637

output:

32858466436756182939

result:

ok answer is '32858466436756182939'

Test #60:

score: 0
Accepted
time: 24ms
memory: 4036kb

input:

10 282614801147051482

output:

5234025743251842898

result:

ok answer is '5234025743251842898'

Test #61:

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

input:

15 973760833528793663

output:

37522313475261748199

result:

ok answer is '37522313475261748199'

Test #62:

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

input:

10 408989789102342508

output:

7507683644212199226

result:

ok answer is '7507683644212199226'

Test #63:

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

input:

18 843218748970858650

output:

48517453136216784320

result:

ok answer is '48517453136216784320'

Test #64:

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

input:

17 278447704544407496

output:

13445647446417261863

result:

ok answer is '13445647446417261863'

Test #65:

score: 0
Accepted
time: 4ms
memory: 3752kb

input:

16 712676664412923638

output:

31626684778484371838

result:

ok answer is '31626684778484371838'

Test #66:

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

input:

11 147905615691505187

output:

3115037238176298995

result:

ok answer is '3115037238176298995'

Test #67:

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

input:

14 814506608119829833

output:

27141557811571426774

result:

ok answer is '27141557811571426774'

Test #68:

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

input:

18 249735567988345974

output:

13745718855311428535

result:

ok answer is '13745718855311428535'

Test #69:

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

input:

17 683964523561894820

output:

34462588212244874220

result:

ok answer is '34462588212244874220'

Test #70:

score: 0
Accepted
time: 9ms
memory: 3848kb

input:

12 119193479135443666

output:

2777183132661531726

result:

ok answer is '2777183132661531726'

Test #71:

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

input:

18 577967474662410047

output:

33372657423746582198

result:

ok answer is '33372657423746582198'