QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#112140 | #1875. Nein | lingchen | WA | 3ms | 3740kb | C++14 | 1.4kb | 2023-06-10 10:53:46 | 2023-06-10 10:53:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t lll;
ll k,n;
lll mod;
lll f[500][5000];
int a[500],s[20];
int blk;
void init()
{
f[0][0]=1;
for(int i=1; i<=40; i++)
for(int j=0; j<=8*(i-1); j++)
for(int k=0; k<9; k++)
f[i][j+k]+=f[i-1][j];
}
lll get(lll x, int z)
{
static lll g[500][5000];
int len=0,b[500],mx=0;
g[0][0]=1;
while(x) b[len++]=x%10, x/=10;
for(int i=0; i<len; i++)
{
int v=z/k;
if(i>=k) v=0;
else if(i<z%k) v++;
int to=(mx+v*8+s[i])/10;
for(int j=0; j<=to; j++) g[i+1][j]=0;
for(int j=0; j<=mx; j++)
{
int tmp=(b[i]-j-s[i]+1000)%10;
for(int q=tmp; q<=v*8; q+=10)
g[i+1][(j+q+s[i])/10]+=g[i][j]*f[v][q];
}
mx=to;
}
return g[len][0];
}
lll calc(int x)
{
lll ans=0;
for(int i=1; i<=blk; i++)
ans+=get(i*mod, x);
return ans;
}
int main()
{
cin>>k>>n; init();
blk=18/k+3; mod=(ll)powl(10, k)-1;
for(int i=40; i>=0; i--)
for(int j=0; j<9; j++)
{
a[i]=j; s[i%k]+=j;
lll cnt=calc(i);
if(cnt<n) n-=cnt;
else break;
s[i%k]-=j;
}
bool flag=0;
for(ll i=40,now=0; i>=0; i--)
{
now=now*10+a[i];
if(flag||now/mod) putchar('0'+now/mod), flag=1;
now%=mod;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
1 1
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
1 8
output:
9
result:
ok answer is '9'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
1 9
output:
12
result:
ok answer is '12'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
1 10
output:
13
result:
ok answer is '13'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
5 1
output:
11112
result:
ok answer is '11112'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
5 84
output:
11235
result:
ok answer is '11235'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
5 668
output:
12345
result:
ok answer is '12345'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
5 733942
output:
2281488
result:
ok answer is '2281488'
Test #9:
score: -100
Wrong Answer
time: 3ms
memory: 3740kb
input:
18 528599760553218747
output:
30741836428166777233
result:
wrong answer expected '30725517742188427234', found '30741836428166777233'