QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345421#4793. QnpKevin5307TL 1467ms22952kbC++202.7kb2024-03-06 22:11:122024-03-06 22:11:13

Judging History

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

  • [2024-03-06 22:11:13]
  • 评测
  • 测评结果:TL
  • 用时:1467ms
  • 内存:22952kb
  • [2024-03-06 22:11:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define sz(v) (int)((v).size())
using ll=long long;
using i128=__int128_t;
const ll thres=(ll)(1e18)+10;
vector<ll> vC[70007];
inline ll C(int n,int k)
{
	k=min(k,n-k);
	return k>=sz(vC[n])?thres:vC[n][k];
}
inline ll mul(ll a,ll b)
{
	return min((i128)(thres),(i128)(a)*b);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=0;i<70007;i++)
	{
		vC[i].resize(min(30,i+1));
		vC[i][0]=1;
		for(int j=1;j<sz(vC[i]);j++)
			if(j==i)
				vC[i][j]=1;
			else
				vC[i][j]=min(thres,vC[i-1][j]+vC[i-1][j-1]);
	}
	int q;
	cin>>q;
	while(q--)
	{
		static int c[12];
		for(int i=0;i<10;i++)
			cin>>c[i];
		int val=*min_element(c,c+10);
		if(val)
		{
			ll k;
			cin>>k;
			const ll mod=1e9+7;
			ll ans=0;
			int cur2=0;
			int sum=accumulate(c,c+10,0);
			ll ways=thres;
			while(sum--)
			{
				int tmp=sum+1;
				while(!c[cur2]) cur2++;
				int mx=*max_element(c,c+10);
				if(ways==thres&&sum-mx<=25)
				{
					ways=1;
					for(int i=cur2;i<9;i++)
					{
						ways=mul(ways,C(tmp,c[i]));
						if(ways==thres) break;
						tmp-=c[i];
					}
				}
				else if(ways==thres)
				{
					c[cur2]--;
					ans=(ans*10+cur2)%mod;
					while(c[cur2]>30)
					{
						c[cur2]--;
						ans=(ans*10+cur2)%mod;
						sum--;
					}
					continue;
				}
				int cur=cur2;
				while(cur<10)
				{
					if(!c[cur])
					{
						cur++;
						continue;
					}
					ll ways2=(ways>=thres?thres:ways*c[cur]/(sum+1));
					if(ways2<k)
					{
						k-=ways2;
						cur++;
					}
					else
					{
						ways=ways2;
						break;
					}
				}
				ans=(ans*10+cur)%mod;
				c[cur]--;
			}
			cout<<ans<<'\n';
		}
		else
		{
			ll k;
			cin>>k;
			const ll mod=1e9+7;
			ll ans=0;
			int cur2=0;
			int sum=accumulate(c,c+10,0);
			ll ways=thres;
			while(sum--)
			{
				int tmp=sum+1;
				while(!c[cur2]) cur2++;
				int mx=*max_element(c,c+10);
				if(ways==thres&&sum-mx<=25)
				{
					ways=1;
					for(int i=cur2;i<9;i++)
					{
						ways=mul(ways,C(tmp,c[i]));
						if(ways==thres) break;
						tmp-=c[i];
					}
				}
				else if(ways==thres)
				{
					c[cur2]--;
					ans=(ans*10+cur2)%mod;
					while(c[cur2]>30)
					{
						c[cur2]--;
						ans=(ans*10+cur2)%mod;
						sum--;
					}
					continue;
				}
				int cur=cur2;
				while(cur<10)
				{
					if(!c[cur])
					{
						cur++;
						continue;
					}
					ll ways2=(ways>=thres?thres:(i128)(ways)*c[cur]/(sum+1));
					if(ways2<k)
					{
						k-=ways2;
						cur++;
					}
					else
					{
						ways=ways2;
						break;
					}
				}
				ans=(ans*10+cur)%mod;
				c[cur]--;
			}
			cout<<ans<<'\n';
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 22752kb

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: 0
Accepted
time: 1461ms
memory: 22760kb

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:

190295171
625739245
198000759
198944878
575159465
972833519
64095209
49623132
936823516
4168747
3116218
789303150
240806129
772063597
812079040
453627969
543807021
604471487
143706250
632200817
838349641
517706711
785181565
476902075
327278139
613377939
161377153
968347598
454781889
685567117
331121...

result:

ok 5000 numbers

Test #3:

score: 0
Accepted
time: 1456ms
memory: 22736kb

input:

5000
3455 3499 3478 3461 3474 3443 3616 38693 3427 3454 930089971600
3510 3489 3483 3425 3561 3436 3489 3544 38519 3544 37094130048
3479 3466 3412 3537 3450 3526 3538 3507 3501 38584 104376751418
3473 3450 3425 3426 3566 38623 3548 3493 3443 3553 237917231736
3635 38357 3579 3506 3593 3492 3528 3483...

output:

684037399
842043368
568045592
676036246
541331596
842972321
946431724
108092521
817901180
345728584
41368985
423510235
996589137
203963496
812764282
342570891
686224841
881783083
579708396
652738341
256857865
94050808
452483230
769258253
742460374
917975
287627317
796397989
20175015
201570167
636403...

result:

ok 5000 numbers

Test #4:

score: 0
Accepted
time: 1444ms
memory: 22952kb

input:

5000
620 64307 623 634 637 677 625 619 648 610 936509154428
64188 667 612 630 653 691 621 604 660 674 616460721378
64379 665 625 628 586 599 637 643 635 603 922333973674
639 643 658 653 64079 680 693 655 681 619 582609184531
637 630 64344 616 674 608 589 654 620 628 738321236380
628 643 667 672 6415...

output:

61909655
865147752
959007350
921107994
877303158
284238808
341484566
559733226
111392185
767325133
539482782
840529796
441813650
308989318
251602327
288433266
77194561
439558615
435343709
167536266
62501465
778738036
15594736
344808793
657976965
55211702
485945122
152327614
157882163
642240818
44638...

result:

ok 5000 numbers

Test #5:

score: 0
Accepted
time: 1467ms
memory: 22704kb

input:

5000
6986 7256 6925 6992 6893 7076 7134 7018 6865 6855 185845197079
6921 7099 6968 6928 6926 7104 7040 7038 7058 6918 34689576688
6969 6967 7032 6697 7259 7101 6953 6980 6964 7078 730823435341
7181 6938 6898 7052 6840 7025 7029 7102 6979 6956 714312003450
6960 7038 7156 6941 6945 6994 6854 7063 7012...

output:

525198628
40498663
20896156
191329603
174782627
654936910
897906363
291982149
149766327
630952451
609027741
489063190
976027933
878296008
72134577
240242785
778213549
415514592
232300725
238143778
242990541
670606889
627453105
537151187
403033727
144945933
293724574
755499297
761451671
214292354
653...

result:

ok 5000 numbers

Test #6:

score: -100
Time Limit Exceeded

input:

5000
7858 7721 7879 7876 0 7850 7636 7782 7745 7653 217256950469
7715 7770 7823 0 7729 7817 7712 7753 7827 7854 743339476766
7714 7744 7891 7852 7772 7704 7725 7796 7802 0 139481058284
0 7720 7790 7773 7847 7724 7930 7806 7702 7708 565137474997
7897 7811 7716 7841 7729 7788 7614 7795 7809 0 97000510...

output:

543230418
219194766
828091313
130085179
717003159
623305812
527475808
586764949
744704294
688568150
216318424
576324749
814990661
589252254
293435668
339632131
183139076
596263592
702994830
813846430
793703949
586658050
725245849
787819031
368055102
532356212
328267412
456770006
828528168
882898896
...

result: