QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#808899 | #4169. 代码拍卖会 | Kevin5307 | 100 ✓ | 35ms | 23488kb | C++23 | 1.7kb | 2024-12-11 09:26:09 | 2024-12-11 09:26:09 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=999911659;
ll inv(ll x)
{
if(x==1) return 1;
return (mod-mod/x)*inv(mod%x)%mod;
}
ll n,p;
ll nxt[505];
int vis[505];
ll c[505];
ll dp[505][10][505];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>p;
for(int i=0;i<p;i++)
nxt[i]=(i*10+1)%p;
int cur=0;
vector<ll> vec;
ll times=n+1;
ll rem;
while(times&&!vis[cur])
{
c[cur]++;
vec.pb(cur);
times--;
vis[cur]=1;
rem=cur;
cur=nxt[cur];
}
if(times)
{
int p=-1;
for(int i=0;i<sz(vec);i++)
if(vec[i]==cur)
p=i;
ll round=sz(vec)-p;
for(int i=p;i<sz(vec);i++)
c[vec[i]]+=times/round;
rem=vec.back();
for(int i=p;i<p+times%round;i++)
{
rem=vec[i];
c[vec[i]]++;
}
}
dp[0][1][rem]=1;
for(int i=0;i<p;i++)
for(int c=0;c<=8;c++)
{
ll ways=1;
for(int x=0;x<c;x++)
ways=ways*((::c[i]+x)%mod)%mod*inv(x+1)%mod;
for(int a=1;a+c<=9;a++)
for(int b=0;b<p;b++)
dp[i+1][a+c][(b+c*i)%p]=(dp[i+1][a+c][(b+c*i)%p]+dp[i][a][b]*ways)%mod;
}
cout<<dp[p][9][0]<<'\n';
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 20ms
memory: 22136kb
input:
982 473
output:
885655151
result:
ok single line: '885655151'
Test #2:
score: 10
Accepted
time: 1ms
memory: 4040kb
input:
82749201374821543 5
output:
209850746
result:
ok single line: '209850746'
Test #3:
score: 10
Accepted
time: 1ms
memory: 3872kb
input:
17327482917364121 7
output:
556848847
result:
ok single line: '556848847'
Test #4:
score: 10
Accepted
time: 0ms
memory: 3636kb
input:
28489124728192763 1
output:
720894199
result:
ok single line: '720894199'
Test #5:
score: 10
Accepted
time: 1ms
memory: 4412kb
input:
40285729174762941 25
output:
370754148
result:
ok single line: '370754148'
Test #6:
score: 10
Accepted
time: 35ms
memory: 23488kb
input:
999999 499
output:
974444728
result:
ok single line: '974444728'
Test #7:
score: 10
Accepted
time: 4ms
memory: 7960kb
input:
58390378572931426 113
output:
633268808
result:
ok single line: '633268808'
Test #8:
score: 10
Accepted
time: 34ms
memory: 22972kb
input:
38475729495732951 491
output:
750948889
result:
ok single line: '750948889'
Test #9:
score: 10
Accepted
time: 25ms
memory: 22780kb
input:
71937591037847128 487
output:
621801725
result:
ok single line: '621801725'
Test #10:
score: 10
Accepted
time: 34ms
memory: 23208kb
input:
100000000000000000 491
output:
725090268
result:
ok single line: '725090268'