QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623301 | #4793. Qnp | Kevin5307 | TL | 61ms | 11280kb | C++23 | 3.8kb | 2024-10-09 11:12:50 | 2024-10-09 11:12:54 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const longer mod=1000000000000000003,mod2=1000000000000001267;
longer ksm(longer a,longer b)
{
longer ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
longer ksm2(longer a,longer b)
{
longer ans=1;
while(b)
{
if(b&1) ans=ans*a%mod2;
b>>=1;
a=a*a%mod2;
}
return ans;
}
longer inv[70007],fact[70007],rfact[70007];
longer inv2[70007],fact2[70007],rfact2[70007];
int cnt[15];
ll sum[70007],pw10[70007];
ll C(int n,int k)
{
if(k<0||k>n) return 0;
return fact[n]*rfact[k]%mod*rfact[n-k]%mod;
}
ll C2(int n,int k)
{
if(k<0||k>n) return 0;
return fact2[n]*rfact2[k]%mod2*rfact2[n-k]%mod2;
}
int main()
{
// freopen("qnp.in","r",stdin);
// freopen("qnp.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
pw10[0]=1;
sum[0]=0;
for(int i=1;i<70007;i++)
{
pw10[i]=pw10[i-1]*10%1000000007;
sum[i]=(sum[i-1]*10+1)%1000000007;
}
for(int i=1;i<70007;i++)
inv[i]=ksm(i,mod-2);
fact[0]=rfact[0]=1;
for(int i=1;i<70007;i++)
{
fact[i]=fact[i-1]*i%mod;
rfact[i]=rfact[i-1]*inv[i]%mod;
}
for(int i=1;i<70007;i++)
inv2[i]=ksm2(i,mod2-2);
fact2[0]=rfact2[0]=1;
for(int i=1;i<70007;i++)
{
fact2[i]=fact2[i-1]*i%mod2;
rfact2[i]=rfact2[i-1]*inv2[i]%mod2;
}
int q;
cin>>q;
int rounds=0;
while(q--)
{
for(int i=0;i<10;i++)
cin>>cnt[i];
ll k;
cin>>k;
int c=accumulate(cnt,cnt+10,0);
ll tot=fact[c];
for(int i=0;i<10;i++)
tot=tot*rfact[cnt[i]]%mod;
ll tott=fact2[c];
for(int i=0;i<10;i++)
tott=tott*rfact2[cnt[i]]%mod2;
ll res=0;
while(c)
{
rounds++;
for(int i=0;i<10;i++) if(cnt[i])
{
ll tot2=tot*inv[c]%mod*cnt[i]%mod;
ll tott2=tott*inv2[c]%mod2*cnt[i]%mod2;
if(tot2>=k||tott2>=k||tot2!=tott2)
{
int L=0,R=cnt[i];
ll tmp3,tmp4,tmpp3;
while(L<R)
{
int mid=(L+R+1)/2;
ll tot4=0;
ll tott4=0;
int x=c-cnt[i];
ll val=fact[x-1],vall=fact2[x-1];
for(int j=0;j<10;j++) if(i!=j)
{
val=val*rfact[cnt[j]]%mod;
vall=vall*rfact2[cnt[j]]%mod2;
}
for(int j=0;j<i;j++) if(cnt[j])
{
ll val2=val*cnt[j]%mod;
ll vall2=vall*cnt[j]%mod2;
// C(x-1+ci-L+1,x-1)+...+C(x-1+ci-1,x-1)
val2=(val2*(C(x+cnt[i]-1,x)-C(x+cnt[i]-mid,x)+mod))%mod;
vall2=(vall2*(C2(x+cnt[i]-1,x)-C2(x+cnt[i]-mid,x)+mod2))%mod2;
tot4=(tot4+val2)%mod;
tott4=(tott4+vall2)%mod2;
}
ll tot3=tot*rfact[c]%mod*fact[c-mid]%mod*fact[cnt[i]]%mod*rfact[cnt[i]-mid]%mod;
ll tott3=tott*rfact2[c]%mod2*fact2[c-mid]%mod2*fact2[cnt[i]]%mod2*rfact2[cnt[i]-mid]%mod2;
int flag=1;
if(tot4>=k||tott4>=k||tot4!=tott4) flag=0;
if(tot4+tot3==tott4+tott3&&tot4+tot3<k) flag=0;
if(flag)
{
tmp3=tot3;
tmp4=tot4;
tmpp3=tott3;
L=mid;
}
else
R=mid-1;
}
res=(res*pw10[L]+sum[L]*i)%1000000007;
k-=tmp4;
tot=tmp3;
tott=tmp3;
cnt[i]-=L;
c-=L;
break;
}
else
k-=tot2;
}
}
cout<<res<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 61ms
memory: 11280kb
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...