QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85174 | #4129. 淘金 | zombie462 | 100 ✓ | 44ms | 7468kb | C++23 | 2.1kb | 2023-03-07 02:18:43 | 2023-03-07 02:18:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 222222
#define LL long long
#define mod 1000000007
LL read(){
LL x=0,f=1;
char ch=getchar();
while (ch<'0' || ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while (ch>='0' && ch<='9'){
x=x*10+ch-'0';ch=getchar();
}
return x*f;
}
struct pt{
int x,y;
LL val;
inline bool operator < (const pt &a) const {
return val<a.val;
}
};
int tot,cnt,len,m;
LL n,k,ans;
int a[15],num[N];
LL b[N*10],dp[15][N][2],siz[N];
priority_queue <pt> q;
pt makept(int x,int y){
pt res;
res.x=x;res.y=y;
res.val=1LL*siz[num[x]]*siz[num[y]];
return res;
}
inline void dfs(int lst,int t,LL sum){
if (sum==0) return;
if (t>len){
b[++cnt]=sum;
return;
}
for (int i=lst;i<=9;++i){
dfs(i,t+1,sum*i);
}
}
inline bool cmp(const int x,const int y){
return siz[x]>siz[y];
}
int main(){
LL n=read(),k=read();
while (n){
a[++len]=n%10;n/=10;
}
dfs(0,0,1);
sort(b+1,b+1+cnt);
cnt=unique(b+1,b+1+cnt)-b-1;
dp[0][2][0]=1;
for (int i=0;i<=len;++i){
for (int j=1;j<=cnt;++j){
for (int k=0;k<=1;++k){
if (!dp[i][j][k]) continue;
for (int p=1;p<=9;++p){
(dp[i+1][lower_bound(b+1,b+1+cnt,b[j]*p)-b][k+p>a[i+1]]+=dp[i][j][k])%=mod;
}
}
}
}
for (int j=1;j<=cnt;++j){
num[j]=j;
for (int i=1;i<len;++i){
siz[j]+=dp[i][j][1]+dp[i][j][0];
}
siz[j]+=dp[len][j][0];
}
sort(num+2,num+1+cnt,cmp);
q.push(makept(2,2));
while (!q.empty()){
pt tmp=q.top();q.pop();
int x=tmp.x,y=tmp.y;
LL val=tmp.val;
ans=(ans+val)%mod;
m++;if (m==k) break;
if (x!=y){
ans=(ans+val)%mod;
q.push(makept(x+1,y));
m++;if (m==k) break;
}
if (x==2) q.push(makept(x,y+1));
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 31ms
memory: 6028kb
input:
993643210231 1
output:
754915436
result:
ok single line: '754915436'
Test #2:
score: 10
Accepted
time: 41ms
memory: 7468kb
input:
1000000000000 99654
output:
252380303
result:
ok single line: '252380303'
Test #3:
score: 10
Accepted
time: 27ms
memory: 5876kb
input:
987656542346 1
output:
606590188
result:
ok single line: '606590188'
Test #4:
score: 10
Accepted
time: 2ms
memory: 3440kb
input:
908 1115
output:
218202
result:
ok single line: '218202'
Test #5:
score: 10
Accepted
time: 44ms
memory: 7456kb
input:
1000000000000 63549
output:
433656825
result:
ok single line: '433656825'
Test #6:
score: 10
Accepted
time: 6ms
memory: 3564kb
input:
884908 89456
output:
621252198
result:
ok single line: '621252198'
Test #7:
score: 10
Accepted
time: 0ms
memory: 3472kb
input:
971257 66548
output:
681002372
result:
ok single line: '681002372'
Test #8:
score: 10
Accepted
time: 31ms
memory: 6008kb
input:
954336460239 96432
output:
522616255
result:
ok single line: '522616255'
Test #9:
score: 10
Accepted
time: 2ms
memory: 3448kb
input:
990 12250
output:
656100
result:
ok single line: '656100'
Test #10:
score: 10
Accepted
time: 30ms
memory: 6008kb
input:
993216540324 89654
output:
372273878
result:
ok single line: '372273878'