QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84607#1875. NeindoctorZ_WA 35ms1872kbC++142.0kb2023-03-06 16:14:312023-03-06 16:14:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 16:14:35]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:1872kb
  • [2023-03-06 16:14:31]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#define int128 __int128
#define ll long long
using namespace std;
const int N=37,S=20*8+20,K=100,P=20;
void write(int128 x)
{
	if(x>=10) write(x/10),putchar('0'+x%10);
	else putchar('0'+x);
}
int k;int128 n,Pow[N+10];
int128 g[K+1][S+10],f[K+2][S+10];
int h[N+10];
int128 get(int128 num)
{
//	write(num);putchar('\n');
	f[0][0]=1;
//	write(f[0][1]);putchar('\n');
//	return 0;
	for(int i=0;i<k;i++)
	{
		for(int s=0;s<=S;s++) f[i+1][s]=0;
		for(int s=0;s<=S;s++)
		{
			if(!f[i][s]) continue;
			int lim=0;
			for(int j=0;i+1+j*k<=N;j++)
				if(h[i+1+j*k]==-1)
					lim++;
				else break;
			int rs=0;
			for(int j=0;i+1+j*k<=N;j++)
				if(h[i+1+j*k]!=-1)
					rs+=h[i+1+j*k];
//			printf("%d %d\n",i,s);
//			printf("%d %d\n",lim,rs);
			for(int s1=0;s1<=S;s1++)
				if(s1+s+rs<=S&&(s1+s+rs)%10==num/Pow[i]%10&&g[lim][s1])
					f[i+1][(s1+s+rs)/10]+=f[i][s]*g[lim][s1];
		}
	}
	int128 ans=0;
	for(int s=0;s<=S;s++)
		if(s==num/Pow[k])
			ans+=f[k][s];
//	write(ans),putchar('\n');
	return ans;
}
int main()
{
//	freopen("a.in","r",stdin);
	scanf("%d",&k);
	ll tmp;scanf("%lld",&tmp);n=tmp;
	g[0][0]=1;
	for(int i=1;i<=N/k+1;i++)
		for(int s=0;s<=S;s++)
			for(int j=0;j<=min(s,8);j++)
				g[i][s]+=g[i-1][s-j];
	Pow[0]=1;for(int i=1;i<=N;i++) Pow[i]=Pow[i-1]*10;
	for(int i=1;i<=N;i++) h[i]=-1;
	int128 nk=Pow[k]-1;
	for(int i=N;i>=1;i--)
	{
		int128 sum=0;
		for(int j=0;j<=8;j++)
		{
			h[i]=j;
			for(int i=1;i<=1;i++)
				sum+=get(nk*i);
//			printf("i %d j %d\n",i,j);
//			write(sum),putchar('\n');
			if(sum>n)
			{
//				h[i]=j-1;
				break;
			}
			if(sum==n)
			{
				break;
			}
		}
		int tmp=h[i];
		sum=0;
		for(int j=0;j<tmp;j++)
		{
			h[i]=j;
			for(int i=1;i<=1;i++)
				sum+=get(nk*i);
		}
		h[i]=tmp;
		n-=sum;
	}
//	return 0;
	int128 ans=0;
	for(int i=N;i>=1;i--)
		if(h[i]!=-1&&h[i])
		{
			ans+=Pow[i-1]*h[i];
//			for(int j=i;j>=1;j--) printf("%d",h[j]);
//			return 0;
		}
	write(ans/nk);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 1736kb

input:

1 1

output:

2

result:

ok answer is '2'

Test #2:

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

input:

1 8

output:

9

result:

ok answer is '9'

Test #3:

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

input:

1 9

output:

12

result:

ok answer is '12'

Test #4:

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

input:

1 10

output:

13

result:

ok answer is '13'

Test #5:

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

input:

5 1

output:

11112

result:

ok answer is '11112'

Test #6:

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

input:

5 84

output:

11235

result:

ok answer is '11235'

Test #7:

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

input:

5 668

output:

12345

result:

ok answer is '12345'

Test #8:

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

input:

5 733942

output:

2281488

result:

ok answer is '2281488'

Test #9:

score: -100
Wrong Answer
time: 35ms
memory: 1496kb

input:

18 528599760553218747

output:

8888888888888888897

result:

wrong answer expected '30725517742188427234', found '8888888888888888897'