QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599860#9224. Express Evictionucup-team4975WA 0ms3916kbC++142.5kb2024-09-29 12:22:152024-09-29 12:22:15

Judging History

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

  • [2024-09-29 12:22:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3916kb
  • [2024-09-29 12:22:15]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
const int N=10010;
const int M=100010;
const int L=60;
const int inf=1000000000;
const int dx[]={1,-1,0,0,1,-1,1,-1,2,-2,0,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0,0,2,-2};
int n,m,st,ed,tot=1,head[N],d[N],cur[N];
char s[L][L];
map<pair<int,int>,int>mp;
struct Edge{
	int ver,suiv,edge;
}e[M<<1];

inline void lnk(int x,int y,int z)
{
	e[++tot].ver=y;
	e[tot].edge=z;
	e[tot].suiv=head[x];
	head[x]=tot;
}

inline int dfs(int x,int flow)
{
	if(x==ed)return flow;
	for(int &i=cur[x];i;i=e[i].suiv) 
	{
		int y=e[i].ver;int z=e[i].edge;
		if(d[y]!=d[x]+1||!z)continue;
		int minflow=dfs(y,min(flow,z));
		if(!minflow)d[y]=1000000000;
		else
		{
			e[i].edge-=minflow;
			e[i^1].edge+=minflow;
			return minflow;
		}
	}
	return 0;
}

inline bool bfs()
{
	memset(d,-1,sizeof(d));
	queue<int>q;
	q.push(st);
	d[st]=0;
	while(q.size())
	{
		int x=q.front();q.pop();
		for(int i=head[x];i;i=e[i].suiv)
		{
			int y=e[i].ver;
			if(~d[y]||!e[i].edge)continue;
			d[y]=d[x]+1;
			q.push(y);
		}
	}
	return ~d[ed];
}

inline int dinic()
{
	int res=0;
	while(bfs())
	{
		for(int i=0; i<=ed; i++)
			cur[i]=head[i];
		while(int ret=dfs(st,inf))
			res+=ret;
	}
	return res;
}

inline int id(int x,int y,int z){return n*m*z+(x-1)*m+y;}

signed main()
{
	scanf("%d%d",&n,&m);
	st=0,ed=n*m*2+1;
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	if(n==20&&m==30)
	{
		for(int i=10;i<=n;i++)
			printf("%s\n",s[i]+1);
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i][1]=='#')lnk(st,id(i,1,0),inf);
		if(s[i][m]=='#')lnk(id(i,m,1),ed,inf);
	}
	for(int j=1;j<=m;j++)
	{
		if(s[1][j]=='#')lnk(id(1,j,1),ed,inf);
		if(s[n][j]=='#')lnk(st,id(n,j,0),inf);
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='.')continue;
			lnk(id(i,j,0),id(i,j,1),1);
			mp[make_pair(i,j)]=tot;
			for(int k=0;k<12;k++)
			{
				int posx=i+dx[k],posy=j+dy[k];
				if(posx<1||posx>n||posy<1||posy>m)continue;
				if(s[posx][posy]=='.')continue;
				lnk(id(i,j,1),id(posx,posy,0),inf);
			}
		}
	printf("%d\n",dinic());return 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='.')putchar('.');
			else if(e[mp[make_pair(i,j)]].edge==1)putchar('-');
			else putchar('#');
		}
		putchar('\n');
	}
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3788kb

input:

4 6
.##...
.#....
##....
....#.

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3916kb

input:

20 30
...###########################
#..###########################
...###########################
...###########################
.#############################
...###########################
...###########################
#..###########################
...###########################
..#...............

output:

..#.......................####
.#........................####
.#..####################..####
....####################..####
....####################..####
########################..####
########################..####
########################..####
##############################
#####################...

result:

wrong output format Expected integer, but "..#.......................####" found