QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89329 | #4129. 淘金 | Purslane | 90 | 37ms | 5492kb | C++14 | 1.9kb | 2023-03-19 19:58:58 | 2023-03-19 19:59:00 |
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});
__int128 ans=0;
ffor(i,1,k) {
__int128 chengji=q.top().chengji,ziji=q.top().ziji; int id=q.top().id;
q.pop(); ans+=chengji;
if(id!=tot) {
++id; q.push({ziji,(__int128)ziji*v[id],id});
}
}
int res=(int)(ans%(1000000000+7));
cout<<res;
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 25ms
memory: 5092kb
input:
993643210231 1
output:
754915436
result:
ok single line: '754915436'
Test #2:
score: 10
Accepted
time: 27ms
memory: 5492kb
input:
1000000000000 99654
output:
252380303
result:
ok single line: '252380303'
Test #3:
score: 10
Accepted
time: 15ms
memory: 5240kb
input:
987656542346 1
output:
606590188
result:
ok single line: '606590188'
Test #4:
score: 10
Accepted
time: 0ms
memory: 3392kb
input:
908 1115
output:
218202
result:
ok single line: '218202'
Test #5:
score: 10
Accepted
time: 22ms
memory: 5440kb
input:
1000000000000 63549
output:
433656825
result:
ok single line: '433656825'
Test #6:
score: 10
Accepted
time: 13ms
memory: 3580kb
input:
884908 89456
output:
621252198
result:
ok single line: '621252198'
Test #7:
score: 10
Accepted
time: 11ms
memory: 3588kb
input:
971257 66548
output:
681002372
result:
ok single line: '681002372'
Test #8:
score: 10
Accepted
time: 37ms
memory: 5116kb
input:
954336460239 96432
output:
522616255
result:
ok single line: '522616255'
Test #9:
score: 0
Wrong Answer
time: 3ms
memory: 3448kb
input:
990 12250
output:
658549
result:
wrong answer 1st lines differ - expected: '656100', found: '658549'
Test #10:
score: 10
Accepted
time: 31ms
memory: 5104kb
input:
993216540324 89654
output:
372273878
result:
ok single line: '372273878'