QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#308319 | #4793. Qnp | KLPP# | TL | 7ms | 17560kb | C++20 | 1.9kb | 2024-01-19 21:58:08 | 2024-01-19 21:58:09 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
const int Mx=1e5;
const lld INF=1e13;
const lld MOD=1e9+7;
lld cnt[10];
vector<lld> comb[Mx];
lld safesum(lld a, lld b){
return min(INF,a+b);
}
lld safemul(lld a, lld b){
if(a==0 || b==0)return 0;
if(a>=(INF/b))return INF;
return a*b;
}
lld safecomb(lld a, lld b){
if(b<0 || b>a)return 0;
if((int)comb[a-b].size()<=b)return INF;
return comb[a-b][b];
}
lld safemulti(lld a, vector<lld> V){
lld cur=a;
lld ans=1;
rep(i,0,(int)V.size()){
ans=safemul(ans,safecomb(cur,V[i]));
cur-=V[i];
}
assert(cur==0);
return ans;
}
lld res;
vector<lld> V;
void constr(lld tot, lld k){
if(tot==0)return;
lld cur=0;
rep(i,0,10){
if(cnt[i]==0)continue;
V.clear();
rep(j,0,10){
V.push_back(cnt[j]-(i==j));
}
lld nxtcur=safesum(cur,safemulti(tot-1,V));
//cout<<cur<<" "<<nxtcur<<" "<<i<<" "<<k<<endl;
if(nxtcur>k){
//cout<<i<<"\n";
res*=10;
res+=i;
res%=MOD;
cnt[i]--;
constr(tot-1,k-cur);
return;
}
cur=nxtcur;
}
}
void solve(){
lld k;
rep(i,0,10)cin>>cnt[i];
cin>>k;
k--;
res=0;
lld tot=0;
rep(i,0,10){
tot+=cnt[i];
}
constr(tot,k);
cout<<res<<"\n";
}
int main(){
rep(i,0,Mx)comb[0].push_back(1);
rep(j,1,Mx){
lld cur=1;
int cnt=0;
do{
//cout<<j<<" "<<cnt<<" "<<cur<<"\n";
comb[j].push_back(cur);
cnt++;
cur=safesum(cur,comb[j-1][cnt]);
}while(cur<INF && cnt<Mx);
}
//~ rep(i,0,20){
//~ rep(j,0,20){
//~ cout<<comb[i][j]<<" ";
//~ }cout<<"\n";
//~ }
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
cin>>tt;
while(tt--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 17560kb
input:
6 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 2 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 2 1 1 1 0 0 0 0 0 0 0 5 1 2 0 0 0 0 0 0 0 0 2
output:
1 10 12 21 201 101
result:
ok 6 numbers
Test #2:
score: -100
Time Limit Exceeded
input:
5000 7142 6835 7022 6981 6929 7008 7038 7015 6885 7145 659213485437 7015 7033 6963 7136 7053 7072 6847 6923 6953 7005 82053183749 7013 7003 6969 7000 7011 7137 7030 6823 7021 6993 817812793310 6893 7008 6963 7086 7012 6922 7128 7094 7028 6866 143084249211 7020 7021 6997 6961 7017 7032 7013 7028 6987...