QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67475 | #4129. 淘金 | alpha1022 | 100 ✓ | 72ms | 127652kb | C++23 | 1.7kb | 2022-12-10 16:19:27 | 2022-12-10 16:19:28 |
Judging History
answer
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int LEN = 13;
const int fact[10][4] = {
{0,0,0,0},
{0,0,0,0},
{1,0,0,0},
{0,1,0,0},
{2,0,0,0},
{0,0,1,0},
{1,1,0,0},
{0,0,0,1},
{3,0,0,0},
{0,2,0,0}
};
const int CNT = 14672;
const int mod = 1e9 + 7;
long long n;
int k;
int tot,d[LEN + 5];
int e[4],cnt;
int c[CNT + 5];
long long f[LEN + 5][LEN * 3 + 5][LEN * 2 + 5][LEN + 5][LEN + 5][2];
long long dfs(int x,int c2,int c3,int c5,int c7,int lead,int top)
{
if(c2 < 0 || c3 < 0 || c5 < 0 || c7 < 0)
return 0;
if(!x)
return !c2 && !c3 && !c5 && !c7;
if(!top && ~f[x][c2][c3][c5][c7][lead])
return f[x][c2][c3][c5][c7][lead];
long long ret = 0;
int bound = top ? d[x] : 9;
for(register int i = (lead && x > 1) ? 0 : 1;i <= bound;++i)
ret += dfs(x - 1,c2 - fact[i][0],c3 - fact[i][1],c5 - fact[i][2],c7 - fact[i][3],lead && !i,top && i == bound);
!top && (f[x][c2][c3][c5][c7][lead] = ret);
return ret;
}
void dfs(int i,long long x)
{
const int d[4] = {2,3,5,7};
if(x > n)
return ;
c[++cnt] = dfs(tot,e[0],e[1],e[2],e[3],1,1);
for(;i < 4;++i)
++e[i],dfs(i,x * d[i]),--e[i];
}
struct note
{
int x,y;
inline bool operator<(const note &o) const
{
return (long long)c[x] * c[y] < (long long)c[o.x] * c[o.y];
}
};
priority_queue<note> q;
int ans;
int main()
{
memset(f,-1,sizeof f);
scanf("%lld%d",&n,&k);
for(register long long i = n;i;d[++tot] = i % 10,i /= 10);
dfs(0,1),k = min(k,cnt * cnt),sort(c + 1,c + cnt + 1);
for(register int i = 1;i <= cnt;++i)
q.push((note){i,cnt});
for(note p;k;--k)
p = q.top(),q.pop(),
ans = (ans + (long long)c[p.x] * c[p.y]) % mod,
p.y > 1 && (--p.y,q.push(p),1);
printf("%d\n",ans);
}
详细
Test #1:
score: 10
Accepted
time: 52ms
memory: 127640kb
input:
993643210231 1
output:
754915436
result:
ok single line: '754915436'
Test #2:
score: 10
Accepted
time: 56ms
memory: 127636kb
input:
1000000000000 99654
output:
252380303
result:
ok single line: '252380303'
Test #3:
score: 10
Accepted
time: 42ms
memory: 127652kb
input:
987656542346 1
output:
606590188
result:
ok single line: '606590188'
Test #4:
score: 10
Accepted
time: 16ms
memory: 127348kb
input:
908 1115
output:
218202
result:
ok single line: '218202'
Test #5:
score: 10
Accepted
time: 37ms
memory: 127584kb
input:
1000000000000 63549
output:
433656825
result:
ok single line: '433656825'
Test #6:
score: 10
Accepted
time: 21ms
memory: 127500kb
input:
884908 89456
output:
621252198
result:
ok single line: '621252198'
Test #7:
score: 10
Accepted
time: 41ms
memory: 127296kb
input:
971257 66548
output:
681002372
result:
ok single line: '681002372'
Test #8:
score: 10
Accepted
time: 65ms
memory: 127508kb
input:
954336460239 96432
output:
522616255
result:
ok single line: '522616255'
Test #9:
score: 10
Accepted
time: 12ms
memory: 127260kb
input:
990 12250
output:
656100
result:
ok single line: '656100'
Test #10:
score: 10
Accepted
time: 72ms
memory: 127536kb
input:
993216540324 89654
output:
372273878
result:
ok single line: '372273878'