QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#112137#1875. NeinlingchenWA 3ms3956kbC++141.4kb2023-06-10 10:51:052023-06-10 10:51:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-10 10:51:10]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3956kb
  • [2023-06-10 10:51:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef __int128_t lll;

ll k,n;
lll mod;
lll f[50][500];
int a[50],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[50][500];
    int len=0,b[50],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)pow(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;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3700kb

input:

1 1

output:

2

result:

ok answer is '2'

Test #2:

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

input:

1 8

output:

9

result:

ok answer is '9'

Test #3:

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

input:

1 9

output:

12

result:

ok answer is '12'

Test #4:

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

input:

1 10

output:

13

result:

ok answer is '13'

Test #5:

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

input:

5 1

output:

11112

result:

ok answer is '11112'

Test #6:

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

input:

5 84

output:

11235

result:

ok answer is '11235'

Test #7:

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

input:

5 668

output:

12345

result:

ok answer is '12345'

Test #8:

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

input:

5 733942

output:

2281488

result:

ok answer is '2281488'

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 3956kb

input:

18 528599760553218747

output:

318686638285214'0(+.

result:

wrong output format 318686638285214'0(+. is not a valid integer