QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89331 | #4129. 淘金 | Purslane | 100 ✓ | 37ms | 5528kb | C++14 | 1.9kb | 2023-03-19 20:02:21 | 2023-03-19 20:02:25 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=30,MOD=1e9+7;
struct INFO {int k,op,sum;}; //op 是否有限制 sum 个数 k 乘积
map<int,int> f; int a[MAXN],tot,ans,n,k,v[100000];
struct Item {__int128 ziji,chengji;int id;};
bool operator <(Item a,Item b) {return a.chengji<b.chengji;}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>k;
int N=n,len=0;
while(N) a[++len]=N%10,N/=10;
vector<INFO> vc;
vc.push_back({1,1,1});
roff(i,len,1) {
vector<INFO> nw;
map<pair<int,int>,int> mp;
for(auto info:vc) {
int k=info.k,op=info.op,sum=info.sum;
if(op) {
ffor(j,1,a[i]) {
int K=k*j,OP=op&(j==a[i]);
if(K<=n) mp[{K,OP}]+=sum;
}
}
else {
ffor(j,1,9) {
int K=k*j,Op=0;
if(K<=n) mp[{K,0}]+=sum;
}
}
}
for(auto info:mp) nw.push_back({info.first.first,info.first.second,info.second});
vc=nw;
}
for(auto pr:vc) f[pr.k]+=pr.sum;
vc.clear();
vc.push_back({1,0,1});
ffor(i,1,len-1) {
vector<INFO> nw;
map<pair<int,int>,int> mp;
for(auto info:vc) {
int k=info.k,op=info.op,sum=info.sum;
ffor(j,1,9) {
int K=k*j,Op=0;
if(K<=n) mp[{K,0}]+=sum;
}
}
for(auto info:mp) nw.push_back({info.first.first,info.first.second,info.second});
vc=nw;
for(auto pr:vc) f[pr.k]+=pr.sum;
}
vector<int> Vc;
for(auto pr:f) Vc.push_back(pr.second);
sort(Vc.begin(),Vc.end(),[](int A,int B) {return A>B;});
for(auto u:Vc) v[++tot]=u;
priority_queue <Item> q;
ffor(i,1,tot) q.push({v[i],(__int128)v[i]*v[1],1});
if(k>tot*tot) k=tot*tot;
int ans=0;
ffor(i,1,k) {
__int128 chengji=q.top().chengji,ziji=q.top().ziji; int id=q.top().id;
q.pop(); ans+=chengji%MOD,ans%=MOD;
if(id!=tot) {
++id; q.push({ziji,(__int128)ziji*v[id],id});
}
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 22ms
memory: 5100kb
input:
993643210231 1
output:
754915436
result:
ok single line: '754915436'
Test #2:
score: 10
Accepted
time: 32ms
memory: 5496kb
input:
1000000000000 99654
output:
252380303
result:
ok single line: '252380303'
Test #3:
score: 10
Accepted
time: 25ms
memory: 5172kb
input:
987656542346 1
output:
606590188
result:
ok single line: '606590188'
Test #4:
score: 10
Accepted
time: 2ms
memory: 3432kb
input:
908 1115
output:
218202
result:
ok single line: '218202'
Test #5:
score: 10
Accepted
time: 19ms
memory: 5528kb
input:
1000000000000 63549
output:
433656825
result:
ok single line: '433656825'
Test #6:
score: 10
Accepted
time: 14ms
memory: 3600kb
input:
884908 89456
output:
621252198
result:
ok single line: '621252198'
Test #7:
score: 10
Accepted
time: 8ms
memory: 3584kb
input:
971257 66548
output:
681002372
result:
ok single line: '681002372'
Test #8:
score: 10
Accepted
time: 37ms
memory: 5140kb
input:
954336460239 96432
output:
522616255
result:
ok single line: '522616255'
Test #9:
score: 10
Accepted
time: 0ms
memory: 3448kb
input:
990 12250
output:
656100
result:
ok single line: '656100'
Test #10:
score: 10
Accepted
time: 37ms
memory: 5140kb
input:
993216540324 89654
output:
372273878
result:
ok single line: '372273878'