QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104993#4793. QnpDeterminantTL 9ms7144kbC++141.3kb2023-05-12 18:22:052023-05-12 18:22:09

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 18:22:09]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:7144kb
  • [2023-05-12 18:22:05]
  • 提交

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[11],st,minn;ll pow0[N],pow1[N],ans,m,inv[N],f[N],f_[N];double s[N];
void sol(){
	ans=st=minn=0;for(int i=0;i<10;++i)scanf("%d",&a[i]),st+=a[i];
	scanf("%lld",&m);double qz=0;ll wz;for(int i=0;i<10;++i)qz-=s[a[i]];
	for(int i=0;i<10;++i)if(a[i]&&qz+s[st-a[i]]+s[a[i]]>13){
		ans=(ans*pow0[a[i]]+pow1[a[i]]*i)%p2;
		st-=a[i],qz+=s[a[i]],a[i]=0;
	}
	wz=f[st];for(int i=0;i<10;++i)wz=(__int128)wz*f_[a[i]]%p;
	while(st){
		int fl;
		for(int i=minn;i<10;++i)if(a[i]){
			if(qz>13&&qz+s[st-1]-s[st]+s[a[i]]-s[a[i]-1]>13){fl=i;break;}
			ll q=(__int128)wz*inv[st]%p*a[i]%p;if(m<=q){fl=i;break;}m-=q;
		}
		ans=(ans*10+fl)%p2;qz+=s[st-1]-s[st]+s[a[fl]]-s[a[fl]-1];
		wz=(__int128)wz*inv[st]%p*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(){
	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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 7144kb

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...

output:

194790992
490841216
759802482
198944878
602833518
527707345
480508598
91669935
354232539
4168747
941213711
793924496
212650013
494495323
763398668
662240824
543807021
910486905
215311279
603777531
79168394
673178176
625783418
476902075
961592653
252706000
107874563
9993689
817857737
414176387
331121...

result: