QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#41196#4376. Dragon slayeryoungsystem#AC ✓375ms3680kbC++2.4kb2022-07-28 17:06:372022-07-28 17:08:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-28 17:08:11]
  • 评测
  • 测评结果:AC
  • 用时:375ms
  • 内存:3680kb
  • [2022-07-28 17:06:37]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<bitset> 
#define mod 1000000007
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
} 
int tsl[20][20][4],nsl[20][20][4];
bool vis[20][20];
int n,m;
void dfs(int x,int y)
{
	if(x<0||x>=n||y<0||y>=m)return;
	if(vis[x][y])return;
//	printf("vis:%d %d\n",x,y);
	vis[x][y]=true;
	if(x>=1&&nsl[x][y][3]==0)dfs(x-1,y);
	if(x<=n-1&&nsl[x][y][1]==0)dfs(x+1,y);
	if(y>=1&&nsl[x][y][2]==0)dfs(x,y-1);
	if(y<=m-1&&nsl[x][y][0]==0)dfs(x,y+1);
}
int lx[20],ly[20],yx[20],yy[20];
int main()
{
	int t,k,xs,ys,xt,yt,ans;
	int x0,y0,x1,y1;
	t=read();
	for(int greg=1;greg<=t;greg++)
	{
		n=read();
		m=read();
		k=read();
		xs=read();
		ys=read();
		xt=read();
		yt=read();
		ans=k;
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=m;j++)
			{
				tsl[i][j][0]=tsl[i][j][1]=tsl[i][j][2]=tsl[i][j][3]=0;
			}
		}
		for(int i=1;i<=k;i++)
		{
			x0=read();
			y0=read();
			x1=read();
			y1=read();
			lx[i]=x0;
			ly[i]=y0;
			yx[i]=x1;
			yy[i]=y1; 
			if(x0==x1)
			{
				if(y0>y1)swap(y0,y1);
				for(int i=y0;i<=y1-1;i++)
				{
					if(x0!=0)tsl[x0-1][i][1]++;
					tsl[x0][i][3]++;
				}
			}
			else
			{
				if(x0>x1)swap(x0,x1);
				for(int i=x0;i<=x1-1;i++)
				{
					if(y0!=0)tsl[i][y0-1][0]++;
					tsl[i][y0][2]++;
				}
			}
		}
		for(int now=1;now<(1<<k);now++)
		{
			for(int i=0;i<=n;i++)
			{
				for(int j=0;j<=m;j++)
				{
					nsl[i][j][0]=tsl[i][j][0];
					nsl[i][j][1]=tsl[i][j][1];
					nsl[i][j][2]=tsl[i][j][2];
					nsl[i][j][3]=tsl[i][j][3];
					vis[i][j]=false;
				}
			}
			for(int j=1;j<=k;j++)
			{
				if((now&(1<<(j-1)))!=0)continue;
				x0=lx[j];
				y0=ly[j];
				x1=yx[j];
				y1=yy[j];
				if(x0==x1)
				{
					if(y0>y1)swap(y0,y1);
					for(int i=y0;i<=y1-1;i++)
					{
						if(x0!=0)nsl[x0-1][i][1]--;
						nsl[x0][i][3]--;
					}
				}
				else
				{
					if(x0>x1)swap(x0,x1);
					for(int i=x0;i<=x1-1;i++)
					{
						if(y0!=0)nsl[i][y0-1][0]--;
						nsl[i][y0][2]--;
					}
				}
			}
			dfs(xs,ys);
			//if(vis[xt][yt])printf("orz%d\n",now);
			if(vis[xt][yt]==true)ans=min(ans,k-__builtin_popcount(now));
		}
		printf("%d\n",ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 375ms
memory: 3680kb

input:

10
4 4 4 0 2 3 3
0 2 4 2
1 3 1 0
2 4 2 1
3 1 3 4
3 2 2 0 0 2 1
0 1 3 1
1 0 1 2
3 2 2 0 0 2 1
2 1 2 2
1 0 1 1
15 15 15 3 12 4 1
8 0 8 15
1 11 15 11
1 1 1 15
3 1 3 15
0 10 14 10
14 1 14 14
8 1 8 15
1 5 14 5
0 15 14 15
0 4 14 4
0 2 15 2
11 0 11 15
4 1 4 15
1 11 15 11
1 12 14 12
15 15 15 8 5 14 0
0 12 1...

output:

1
2
0
5
3
5
1
4
1
0

result:

ok 10 lines