QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#795630#9599. Dragon BloodlineYaimsea#WA 109ms8596kbC++201.7kb2024-11-30 22:23:072024-11-30 22:23:07

Judging History

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

  • [2024-11-30 22:23:07]
  • 评测
  • 测评结果:WA
  • 用时:109ms
  • 内存:8596kb
  • [2024-11-30 22:23:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll maxr=1e16;
int n,k,maxa,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)
			{
				//printf("??? %lld %lld %lld\n",j,c[i-1][j],book[c[i-1][j]]);
				if(book[c[i-1][j]])
				{
					--las,book[c[i-1][j]]=0;
					//if(x==5)
						//printf("??? %lld\n",las);
					if(!las)
					{
						vis=1;
						break;
					}
				}
			}
			//if(x==5)
				//printf("???\n");
			if(!vis)
				return 1;
		}
		else
			sum-=b[i];
	}
	return (!sum);
}
int main()
{
	int i,T;
	ll l,r,mid;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&n,&k);
		maxa=0;
		for(i=1;i<=n;++i)
		{
			scanf("%d",&a[i]);
			maxa=max(maxa,a[i]);
		}
		for(i=0;i<k;++i)
			scanf("%d",&b[i]);
		ans=0,l=1,r=maxr/maxa;
		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: 5976kb

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: 6048kb

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: 3812kb

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: -100
Wrong Answer
time: 109ms
memory: 8596kb

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:

10000000000000000

result:

wrong answer 1st lines differ - expected: '1048575', found: '10000000000000000'