High Buildings KickStart2020 Round E

https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ff47/00000000003bef73

Special judgment for 1 2

Then if we need AC 2 on the left for the people on the left to see, BC 2 on the right for the people on the right to see, C n in the middle for both people to see, and 1 for the remaining insufficient positions, but 1 It must be blocked, so when C>2, 1 is placed in the middle of C, if AC>0, it is placed between 2 and n on the left, and BC>0 is placed between n and 2 on the right, otherwise there is no solution

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;

const int maxl=3e5+10;

int n,m,cas,k,cnt,tot,ans;
int A,B,C;
int a[maxl],b[maxl];
char s[maxl];
bool in[maxl]; 

inline void prework()
{
	scanf("%d%d%d%d",&n,&A,&B,&C);
} 

inline void mainwork()
{
	ans=0;
	if(A-C+B-C+C>n || C>n || C<=0)
	{
		ans=0;
		return;
	}
	if(n==1)
	{
		if(A!=1 || B!=1 || C!=1)
		{
			ans=0;return;
		}
		ans=1;a[1]=1;return;
	}
	if(n==2)
	{
		if(C==2 && A==2 && B==2)
		{
			ans=1;a[1]=1;a[2]=1;
		}
		if(C==1 && A==2 && B==1)
		{
			ans=1;a[1]=1;a[2]=2;
		}
		if(C==1 && A==1 && B==2)
		{
			ans=1;a[1]=2;a[2]=1;
		}
		return;
	}
	cnt=0;
	if(C>=2)
	{
		ans=1;
		for(int i=1;i<=A-C;i++)
			a[++cnt]=2;
		a[++cnt]=n;
		for(int i=1;i<=n-(A-C+B-C+C);i++)
			a[++cnt]=1;
		for(int i=2;i<=C;i++)
			a[++cnt]=n;
		for(int i=1;i<=B-C;i++)
			a[++cnt]=2;
	}
	else if(A-C>0)
	{
		ans=1;
		for(int i=1;i<=A-C;i++)
			a[++cnt]=2;
		for(int i=1;i<=n-(A-C+B-C+C);i++)
			a[++cnt]=1;
		for(int i=1;i<=C;i++)
			a[++cnt]=n;
		for(int i=1;i<=B-C;i++)
			a[++cnt]=2;
	}
	else if(B-C>0)
	{
		ans=1;
		for(int i=1;i<=A-C;i++)
			a[++cnt]=2;
		for(int i=1;i<=C;i++)
			a[++cnt]=n;
		for(int i=1;i<=n-(A-C+B-C+C);i++)
			a[++cnt]=1;
		for(int i=1;i<=B-C;i++)
			a[++cnt]=2;		
	}
	else
		ans=0;
}

inline void print()
{
	printf("Case #%d:",cas);
	if(!ans)
		puts(" IMPOSSIBLE");
	else
	{
		for(int i=1;i<=n;i++)
			printf(" %d",a[i]);
		puts("");
	}
}

int main()
{
	int t=1;
	scanf("%d",&t);
	for(cas=1;cas<=t;cas++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

 

Guess you like

Origin blog.csdn.net/liufengwei1/article/details/108191996