QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84795#1875. NeinruizhangjTL 0ms0kbC++142.2kb2023-03-06 18:57:522023-03-06 18:57:54

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 18:57:54]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-03-06 18:57:52]
  • 提交

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef __int128 I;
typedef __uint128_t I;
const int AnsW=38,Max=340;
int num[40][20];
I f[2][Max];
ll n,Mod=1;
int w,z;
void init(){
	scanf("%d%lld",&w,&n);
	for (int i=1;i<=w;++i) Mod*=10ll;
	--Mod;
	memset(num,-1,sizeof(num));
	z=(AnsW+w-1)/w;
	for (int i=1;i<=w;++i) if (z*w-i+1>AnsW) num[z][w-i+1]=0;
}
I calc(int ei,int ej){
	if (ej==1) --ei,ej=w;
	else --ej;
	I res=0;
	for (int p=0;p<=z;++p){
		for (int si=z;si>=ei;--si)
			for (int sj=w;sj>=(si==ei?ej:1);--sj){
				memset(f,0,sizeof(f));
				I v=p*Mod;
				int now=0;
				f[now][0]=1,f[now][1]=-1;
				for (int j=1;j<=w;++j){
					for (int i=z;i>=1;--i){
						for (int k=1;k<Max;++k) f[now][k]+=f[now][k-1];
						for (int k=0;k<Max;++k) f[now^1][k]=0;
						int l=-1,r=-1;
						if (i>si || i==si && j>sj) l=num[i][j],r=num[i][j];
						else if (i==si && j==sj){
							if (num[i][j]==-1) l=0,r=8;
							else l=0,r=num[i][j]-1;
						}
						else l=0,r=8;
						if (l<=r){
							for (int k=0;k+l<Max;++k){
								f[now^1][k+l]+=f[now][k];
								if (k+r+1<Max) f[now^1][k+r+1]-=f[now][k];
							}
						}
						now^=1;
					}
					for (int k=1;k<Max;++k) f[now][k]+=f[now][k-1];
					for (int k=0;k<Max;++k) f[now^1][k]=0;
					for (int k=0;k<Max;++k)
						if (k%10==v%10)
							f[now^1][k/10]+=f[now][k],f[now^1][k/10+1]-=f[now][k];
					now^=1;
					v/=10;
				}
				for (int k=1;k<Max;++k) f[now][k]+=f[now][k-1];
				if (v<Max) res+=f[now][v];
			}
	}
	return res-1;
}
int pr[105],l=0;
void write(I x){
	if (!x) putchar('0');
	for (;x;x/=10) pr[++l]=x%10;
	for (;l;--l) putchar(pr[l]+'0');
	puts("");
}
void work(){
	for (int i=z;i>=1;--i)
		for (int j=w;j>=1;--j)
			if (num[i][j]==-1){
				int l=0,r=8,res=0;
				while (l<=r){
					int mid=(l+r)>>1;
					num[i][j]=mid;
					if (calc(i,j)>=n) r=mid-1,res=mid;
					else l=mid+1;
				}
				num[i][j]=res;
			}
	I ans=0;
	for (int i=z;i>=1;--i)
		for (int j=w;j>=1;--j)
			ans=10*ans+num[i][j];
	ans/=Mod;
//	puts("");
	write(ans);
}
int main(){
//	freopen("a.in","r",stdin);
	init();
	work();
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

1 1

output:


result: