QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795647 | #9599. Dragon Bloodline | Yaimsea# | WA | 100ms | 8536kb | C++20 | 1.6kb | 2024-11-30 22:39:03 | 2024-11-30 22:39:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll maxr=1e16;
int n,k,a[50010],b[30];
int cnt,book[50010];
int c[20][50010];
ll ans,p[50010];
bool check(ll x)
{
int i,j,las,vis;
ll sum=0;
for(i=1;i<=n;++i)
p[i]=x*a[i],book[i]=1;
for(i=1;i<=n;++i)
sum+=(p[i]/(1<<k));
cnt=0;
for(i=1;i<=n;++i)
{
if(p[i]&1)
c[0][++cnt]=i;
}
for(i=1;i<=n;++i)
{
if(!(p[i]&1))
c[0][++cnt]=i;
}
for(i=1;i<k;++i)
{
cnt=0;
for(j=1;j<=n;++j)
{
if(p[c[i-1][j]]&(1<<i))
c[i][++cnt]=j;
}
for(j=1;j<=n;++j)
{
if(!(p[c[i-1][j]]&(1<<i)))
c[i][++cnt]=j;
}
}
//printf("??? %lld %lld\n",x,sum);
for(i=k-1;i>=0;--i)
{
sum<<=1;
for(j=1;j<=n;++j)
{
if(book[j])
sum+=((p[j]&(1<<i))?1:0);
}
//if(x==5)
//printf("!!! %lld %lld %lld\n",sum,i,b[i]);
if(sum<b[i])
{
if(!i)
return 1;
las=b[i]-sum;
sum=0;
vis=0;
for(j=1;j<=n;++j)
{
if(book[c[i-1][j]])
{
--las,book[c[i-1][j]]=0;
if(!las)
{
vis=1;
break;
}
}
}
if(!vis)
return 1;
}
else
sum-=b[i];
}
return (!sum);
}
int main()
{
int i,T;
ll l,r,mid,suma;
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&n,&k);
suma=0;
for(i=1;i<=n;++i)
{
scanf("%d",&a[i]);
suma+=a[i];
}
for(i=0;i<k;++i)
scanf("%d",&b[i]);
ans=0,l=1,r=maxr/suma;
while(l<=r)
{
mid=(l+r)>>1;
if(check(mid))
ans=mid,l=mid+1;
else
r=mid-1;
}
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6044kb
input:
6 4 3 1 2 3 4 4 4 4 3 2 1 1 1 1 7 3 4 6 6 2 1 1 5 5 3 5 3 1 1 1 1 1 1 1 4 5 1 9 9 8 2 2 2 3 1 5 4 1 3 1 7 1 4 1 5 2
output:
2 4 4 5 2 3
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 6024kb
input:
1 1 20 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1048575000000000
result:
ok single line: '1048575000000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 7896kb
input:
2 3 2 1 1 1 1 7 4 2 1 1 1 1 1 2
output:
4 0
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 84ms
memory: 8536kb
input:
1 50000 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
1048575
result:
ok single line: '1048575'
Test #5:
score: -100
Wrong Answer
time: 100ms
memory: 5884kb
input:
1000 37 20 2 8 8 7 8 7 4 6 7 4 7 4 8 4 4 5 8 3 5 5 7 7 10 6 3 2 5 3 5 8 3 6 2 4 7 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 12 4 7 12 6 12 18 11 35 19 3 8 2 6 3 6 4 3 8 4 4 9 26 13 9 9 5 3 4 5 2 10 4 6 6 9 5 3 9 10 6 2 10 4 2 9 9 3 9 3 1 1 1 1 1 1 1 1 1 1 1 1 1 33 18 3 5 3 3 4 1 4 3 1 4 5 1 3 4 ...
output:
0 222 0 10566 0 0 0 4 0 52 0 44 2 0 21 4 2 18 0 11 0 21 0 0 1478 27 0 382 108 5 0 17 0 12 0 0 0 0 3255 525 0 189 0 0 1615 0 0 0 0 0 63 0 2 2 5 68 314 118 0 0 5 0 3822 0 86 0 1 0 0 0 29 0 0 50 77 112 0 0 3 80 0 0 1578 0 0 4863 1535 0 0 0 21 20 0 5 0 69222 204 0 0 3 0 0 75 33 0 0 0 0 0 0 60 0 0 0 0 0 ...
result:
wrong answer 4th lines differ - expected: '18103', found: '10566'