QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84803 | #1875. Nein | ruizhangj | TL | 0ms | 0kb | C++14 | 2.2kb | 2023-03-06 19:13:40 | 2023-03-06 19:13:43 |
Judging History
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 Max=340;
const int AnsW=39;
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;
// int AnsW=20+w;
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){
// printf("%d %d\n",i,j);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1 1