QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220437 | #7613. Inverse Problem | ucup-team2303# | TL | 0ms | 0kb | C++14 | 2.0kb | 2023-10-20 12:54:05 | 2023-10-20 12:54:06 |
answer
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,fac[1000001],inv[1000001],st[1000001],u[1000001],g[100001],lim=1e15;
char s[1000001];
struct p{long long q,w;}l[1000001];
long long pow_(long long qq,long long ww){long long ee=1;while(ww){if(ww&1) ee*=qq,ee%=mod;qq*=qq,qq%=mod,ww>>=1;}return ee%mod;}
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww){l[++o].q=ww,l[o].w=h[qq],h[qq]=o;}
long long gcd(long long qq,long long ww){return !ww?qq:gcd(ww,qq%ww);}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
long long C(long long qq,long long ww){return fac[qq]*inv[ww]%mod*inv[qq-ww]%mod;}
bool ch(long long qq)
{
for(int i=0;i<=60;i++) v[i]=g[i]=0;
for(int i=a;i>a-qq;i--)
{
if(d[i]>0) g[d[i]-1]++;
}
for(int i=1;i<=a-qq;i++)
{
v[d[i]]++;
}
for(int i=50;i>=0;i--)
{
if(g[i]<v[i]) return 0;
if(i>0) g[i-1]+=v[i];
g[i]-=v[i],v[i]=0;
if(i>0) g[i-1]=min(lim,g[i-1]+g[i]*2);
}
return 1;
}
int main()
{
// freopen("1.in","r",stdin);
srand((unsigned)(time(0)^(*new int)));
fac[0]=1;for(int i=1;i<=1000000;i++) fac[i]=fac[i-1]*i%mod;
inv[1000000]=pow_(fac[1000000],mod-2);for(int i=999999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
T=1;
scanf("%lld",&T);
for(int ii=1;ii<=T;ii++)
{
scanf("%lld",&a);
for(int i=1;i<=a;i++) d[i]=read();
sort(d+1,d+a+1);
for(int i=0;i<=60;i++) v[i]=g[i]=0;
for(int i=1;i<=a;i++)
{
long long tt=d[i];cn=0;
while(tt%2==0) tt/=2,++cn;
d[i]=cn;
}an=0;
long long ll=1,rr=a;an=0;
while(ll<=rr)
{
long long mid=((ll+rr)>>1);
if(!ch(mid)) ll=mid+1;
else rr=mid-1,an=mid;
}
printf("%lld\n",an);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
4 2 360 1 509949433