QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345709 | #4793. Qnp | Kevin5307 | TL | 1495ms | 23368kb | C++20 | 2.4kb | 2024-03-07 12:43:25 | 2024-03-07 12:43:26 |
Judging History
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)
{
if(1.*a*b>thres) return thres;
return a*b;
}
ll val[70007];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(int i=1;i<70007;i++)
val[i]=thres/i+(i!=1);
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];
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=0;
for(int i=0;i<10;i++)
mx=max(mx,c[i]);
if(ways==thres&&sum-mx<=25)
{
if(mx>25)
{
int pos=0;
for(int i=0;i<10;i++)
if(c[i])
{
pos=i;
break;
}
int l=0,r=c[pos];
while(l<r)
{
int mid=(l+r)/2;
ll tmp=1;
int total=sum+1-c[pos]+mid;
for(int i=0;i<10;i++)
{
int cur=(i==pos?mid:c[i]);
tmp=mul(tmp,C(total,cur));
total-=cur;
}
assert(!total);
if(tmp<k)
l=mid+1;
else
r=mid;
}
if(l!=c[pos])
{
ans=(ans*10+pos)%mod;
c[pos]--;
while(c[pos]!=l)
{
c[pos]--;
sum--;
ans=(ans*10+pos)%mod;
}
continue;
}
}
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>=val[c[cur]]?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';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 23368kb
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: 1486ms
memory: 23316kb
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: 1479ms
memory: 23272kb
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: 1471ms
memory: 23352kb
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: 1488ms
memory: 23304kb
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: 0
Accepted
time: 1495ms
memory: 23272kb
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:
ok 5000 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
5000 8600 8810 8802 8773 0 8900 0 8755 8754 8606 185744757952 8646 8807 8595 8647 8943 8883 8706 0 0 8773 244618258913 8822 8732 8902 0 8816 8866 8483 8533 0 8846 862528700594 8801 0 8470 0 8715 8777 8952 8748 8752 8785 603858597601 8732 8651 8625 8796 8797 8946 8776 0 8677 0 310763524447 7670 0 783...
output:
478515677 966769933 949449612 23764448 289281232 926577329 602199711 136391452 471884979 386022965 468684911 441883139 459650490 649702684 148743528 235767171 100161607 694671059 646145267 234169531 954077728 358011353 142741442 452149967 234082492 434079473 688498761 693161665 98099547 919335416 13...