QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#105135 | #4793. Qnp | Determinant | WA | 5ms | 7104kb | C++14 | 2.3kb | 2023-05-13 12:42:05 | 2023-05-13 12:42:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;typedef long long ll;
const int N=70007;const ll p=1445141919821ll,p2=1e9+7;
int a[11],st,minn,fl,cnt;ll pow0[N],pow1[N],ans,m,inv[N],f[N],f_[N];double s[N];
void sol(){
ans=st=0;for(int i=0;i<10;++i)scanf("%d",&a[i]),st+=a[i];
scanf("%lld",&m);double qu=0;ll wz=1;
for(int i=0;i<10;++i)qu-=s[a[i]],wz=(__int128)wz*f_[a[i]]%p;
for(int i=0;i<10;++i)if(a[i]){
if(qu+s[st-a[i]]+s[a[i]]>12.1||m<=(__int128)wz*f[st-a[i]]*f[a[i]]%p){
qu+=s[a[i]];ans=(ans*pow0[a[i]]+pow1[a[i]]*i)%p2;
wz=(__int128)wz*f[a[i]]%p;st-=a[i];a[i]=0;
}
else{minn=i;break;}
}
while(st){
ll m_=m;for(int i=minn;i<10;++i)if(a[i]){
if(qu+s[st-1]+s[a[i]]-s[a[i]-1]>12.1){fl=i;break;}
ll q=(__int128)wz*f[st-1]*a[i]%p;if(m<=q){fl=i;break;}m-=q;
}
int qc=0;for(int i=0;i<10;++i)if(a[i])qc++;
if(qc==2&&fl>minn&&qu+s[st]<12.1){
int l=1,r=a[fl]+1,mid;ll qt=(__int128)wz*f[st]%p-m_;
while(l<r){
mid=(l+r)/2;
if((__int128)f[st-mid]*f_[a[fl]-mid]*f_[a[minn]]%p<=qt)r=mid;
else l=mid+1;
}
m=m_-(__int128)wz*f[st]%p+(__int128)
f[st-(l-1)]*f_[a[fl]-(l-1)]*f_[a[minn]]%p;
ans=(ans*pow0[l]+pow1[l]*9+p2-1)%p2;
st-=l;a[fl]-=l-1;a[minn]--;qu=-s[a[minn]]-s[a[fl]];
wz=(__int128)f_[a[minn]]*f_[a[fl]]%p;
}
else if(fl==minn&&a[minn]>8&&(qu+s[st-8]+s[a[minn]]-s[a[minn]-8]>12.1||
m<=(__int128)wz*f[st-8]*f[a[minn]]%p*f_[a[minn]-8]%p)){
int l=0,r=a[minn],mid;
while(l<r){
mid=(l+r+1)/2;if(qu+s[st-mid]+s[a[minn]]-s[a[minn]-mid]>12.1||
m<=(__int128)wz*f[st-mid]*f[a[minn]]%p*f_[a[minn]-mid]%p)l=mid;
else r=mid-1;
}
qu+=s[a[minn]]-s[a[minn]-l];wz=(__int128)wz*f[a[minn]]*f_[a[minn]-l]%p;
ans=(ans*pow0[l]+pow1[l]*minn)%p2;st-=l;a[minn]-=l;
}
else{ans=(ans*10+fl)%p2;qu+=s[a[fl]]-s[a[fl]-1];wz=(__int128)wz*a[fl]%p;st--;a[fl]--;}
if(!a[minn]){for(int i=0;i<10;++i)if(a[i]){minn=i;break;}}
}
printf("%lld\n",ans);return;
}
int main(){
//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
inv[1]=1;for(int i=2;i<N;++i)inv[i]=(__int128)(p-p/i)*inv[p%i]%p;
f[0]=f_[0]=pow0[0]=1;for(int i=1;i<N;++i){
f[i]=(__int128)f[i-1]*i%p,f_[i]=(__int128)f_[i-1]*inv[i]%p;
s[i]=s[i-1]+log10(i);pow1[i]=(pow1[i-1]*10+1)%p2;
pow0[i]=pow0[i-1]*10%p2;
}
int t;scanf("%d",&t);while(t--)sol();return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 7104kb
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 98 12 98 201 981
result:
wrong answer 2nd numbers differ - expected: '10', found: '98'