QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#31778#1197. Draw in Straight LinesWu_RenRE 3ms5960kbC++141.8kb2022-05-12 16:09:012022-05-12 16:09:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-12 16:09:02]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:5960kb
  • [2022-05-12 16:09:01]
  • 提交

answer

#include <bits/stdc++.h>
const int inf=2e9;
using namespace std;
int n,m,a,b,c,Hb[45][45],Hw[45][45],Vb[45][45],Vw[45][45],S,T,cnt=0,head[1610],o=1,cur[1610],dep[1610];
char s[50];
struct edge{
	int to,link,w;
}e[200000];
void add_edge(int u,int v,int w){
	e[++o]={v,head[u],w},head[u]=o;
	e[++o]={u,head[v],0},head[v]=o;
}
queue<int>q;
bool bfs(){
	for(int i=1;i<=cnt;i++) cur[i]=head[i],dep[i]=0;
	dep[S]=1,q.push(S);
	while(q.size()){
		int u=q.front();q.pop();
		for(int i=head[u],v;i;i=e[i].link) if(!dep[v=e[i].to]&&e[i].w){
			dep[v]=dep[u]+1,q.push(v);
		}
	}
	return dep[T];
}
int dfs(int u,int in){
	if(u==T) return in;
	int out=0;
	for(int &i=cur[u],v;i;i=e[i].link) if(dep[v=e[i].to]==dep[u]+1&&e[i].w){
		int res=dfs(v,min(in,e[i].w));
		e[i].w-=res,e[i^1].w+=res;
		in-=res,out+=res;
		if(!in) break;
	}
	if(!out) dep[u]=0;
	return out;
}
int main(){
	scanf("%d%d%d%d%d",&n,&m,&a,&b,&c);
	S=++cnt,T=++cnt;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
		Hb[i][j]=++cnt,Hw[i][j]=++cnt;
		Vb[i][j]=++cnt,Vw[i][j]=++cnt;
		add_edge(S,Hb[i][j],a);
		add_edge(Hw[i][j],T,a);
		add_edge(S,Vw[i][j],a);
		add_edge(Vb[i][j],T,a);
		if(i>1){
			add_edge(Hb[i][j],Hb[i-1][j],b);
			add_edge(Hw[i-1][j],Hw[i][j],b);
		}
		if(i==n){
			add_edge(S,Hb[i][j],b);
			add_edge(Hw[i][j],T,b);
		}
		if(j>1){
			add_edge(Vw[i][j],Vw[i][j-1],b);
			add_edge(Vb[i][j-1],Vb[i][j],b);
		}
		if(j==m){
			add_edge(S,Vw[i][j],b);
			add_edge(Vb[i][j],T,b);
		}
	}
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) if(s[j]=='#'){
			add_edge(Hb[i][j],Vb[i][j],c);
			add_edge(Hw[i][j],T,inf);
			add_edge(S,Vw[i][j],inf);
		}
		else{
			add_edge(Vw[i][j],Hb[i][j],c);
			add_edge(Vb[i][j],Hw[i][j],c);
			add_edge(Vb[i][j],Hb[i][j],inf);
		}
	}
	int ans=0;
	while(bfs()) ans+=dfs(S,inf);
	printf("%d\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3864kb

input:

3 3 1 2 3
.#.
###
.#.

output:

10

result:

ok answer is '10'

Test #2:

score: 0
Accepted
time: 2ms
memory: 5960kb

input:

2 7 0 1 1
###.###
###.###

output:

3

result:

ok answer is '3'

Test #3:

score: 0
Accepted
time: 3ms
memory: 3872kb

input:

5 5 1 4 4
..#..
..#..
##.##
..#..
..#..

output:

24

result:

ok answer is '24'

Test #4:

score: 0
Accepted
time: 3ms
memory: 3840kb

input:

7 24 1 10 10
###...###..#####....###.
.#...#...#.#....#..#...#
.#..#......#....#.#.....
.#..#......#####..#.....
.#..#......#......#.....
.#...#...#.#.......#...#
###...###..#........###.

output:

256

result:

ok answer is '256'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3832kb

input:

5 5 0 3 2
..#..
..#..
##.##
..#..
..#..

output:

11

result:

ok answer is '11'

Test #6:

score: -100
Runtime Error

input:

40 40 40 40 40
########################################
########################################
########################################
########################################
########################################
########################################
#######################################...

output:


result: