QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88416#1197. Draw in Straight LineshellojimRE 2ms3596kbC++142.5kb2023-03-16 10:45:542023-03-16 10:45:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 10:45:56]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3596kb
  • [2023-03-16 10:45:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=42*42*2,M=42*42*20;
const int inf=1e9;
int n,m,a,b,c,s,t; 
struct edge{
	int v,nxt,w;
}e[M];
int head[N],cur[N];
int cnt=1,tot=0;
void addedge(int u,int v,int w){
	++cnt;
	e[cnt].v=v;e[cnt].w=w;e[cnt].nxt=head[u];head[u]=cnt;
}
int dep[N];
bool bfs(){
	for(int i=1;i<=t;i++){
		dep[i]=0;cur[i]=head[i];
	}
	queue<int>q;q.push(s);
	dep[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int p=head[u];p;p=e[p].nxt){
			int v=e[p].v;
			if(!dep[v]&&e[p].w){
				dep[v]=dep[u]+1;
				q.push(v);
			}
		}
	}
	return dep[t]!=0;
}
int dfs(int u,int in){
	if(u==t)return in;
	int out=0;
	for(int p=cur[u];p;p=e[p].nxt){
		cur[u]=p;
		int v=e[p].v;
		if(e[p].w&&dep[v]==dep[u]+1){
			int x=dfs(v,min(in,e[p].w));
			in-=x;out+=x;
			e[p].w-=x;e[p^1].w+=x;
		}
		if(!in)break; 
	}
	if(!out)dep[u]=0;
	return out;
}
int maxflow(){
	int ans=0;
	while(bfs())ans+=dfs(s,inf);
	return ans;
}
string str[42];
int bn[42][42],bm[42][42],wn[42][42],wm[42][42];
void adde(int u,int v,int w){
	addedge(u,v,w);addedge(v,u,0);
}
int main(){
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m>>a>>b>>c;
	for(int i=1;i<=n;i++){
		cin>>str[i];str[i]=' '+str[i];
		for(int j=1;j<=m;j++){
			bn[i][j]=++tot;wn[i][j]=++tot;
			bm[i][j]=++tot;wm[i][j]=++tot;
		} 
	} 
	s=++tot;t=++tot;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(str[i][j]=='#'){
				adde(s,bn[i][j],a);
				adde(bn[i][j],bm[i][j],c);
				adde(bm[i][j],t,a);
				adde(s,wm[i][j],inf);
				adde(wn[i][j],t,inf);
				if(i==1){
					adde(s,bn[i][j],b);
					adde(wn[i][j],t,b);
				}
				else{
					adde(bn[i-1][j],bn[i][j],b);
					adde(wn[i][j],wn[i-1][j],b);
				}
				if(j==1){
					adde(bm[i][j],t,b);
					adde(s,wm[i][j],b);
				}
				else{
					adde(bm[i][j],bm[i][j-1],b);
					adde(wm[i][j-1],wm[i][j],b);
				}
			}
			else{
				adde(s,bn[i][j],a);
				adde(bm[i][j],bn[i][j],inf);
				adde(bm[i][j],t,a);
				adde(s,wm[i][j],a);
				adde(wm[i][j],bn[i][j],c);
				adde(wn[i][j],t,a);
				adde(bm[i][j],wn[i][j],c);
				if(i==1){
					adde(s,bn[i][j],b);
					adde(wn[i][j],t,b);
				}
				else{
					adde(bn[i-1][j],bn[i][j],b);
					adde(wn[i][j],wn[i-1][j],b);
				}
				if(j==1){
					adde(bm[i][j],t,b);
					adde(s,wm[i][j],b);
				}
				else{
					adde(bm[i][j],bm[i][j-1],b);
					adde(wm[i][j-1],wm[i][j],b);
				}
			}
		}
	}
	cout<<maxflow()<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3552kb

input:

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

output:

10

result:

ok answer is '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3392kb

input:

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

output:

3

result:

ok answer is '3'

Test #3:

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

input:

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

output:

24

result:

ok answer is '24'

Test #4:

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

input:

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

output:

256

result:

ok answer is '256'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3372kb

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: