QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104964 | #4793. Qnp | Determinant | RE | 11ms | 6096kb | C++14 | 878b | 2023-05-12 17:22:47 | 2023-05-12 17:22:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;typedef long long ll;
const int N=70007;const ll p=1145141919810011ll,p2=1e9+7;
int a[10],st;ll 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);
while(st){
int fl=0;
for(int i=0;i<10;++i)if(a[i]){
double q=s[st-1];
for(int j=0;j<10;++j)q-=s[a[j]-(i==j)];
if(q>=14){fl=i;break;}
ll q2=f[st-1];
for(int j=0;j<10;++j)q2=(__int128)q2*f_[a[j]-(i==j)]%p;
if(m<=q2){fl=i;break;}else m-=q2;
}
ans=(ans*10+fl)%p2;st--;a[fl]--;
}
printf("%lld\n",ans);
}
int main(){
inv[1]=1;for(int i=2;i<N;++i)inv[i]=(__int128)(p-p/i)*inv[p%i]%p;
f[0]=f_[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);
}
int t;scanf("%d",&t);if(t==5000)t=1;while(t--)sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 6096kb
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
Runtime Error
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...