QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74759 | #1197. Draw in Straight Lines | 18Michael | RE | 13ms | 3756kb | C++14 | 2.1kb | 2023-02-03 19:59:03 | 2023-02-03 19:59:05 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 70000
using namespace std;
const int MxV=1612,MxE=70002;
int n,m,a,b,c,S=0,T,tot=0,p,edge_t=1;
int la[MxV],cur[MxV],dis[MxV];
int br[42][42],wr[42][42],bc[42][42],wc[42][42];
char s[42][42];
queue<int> q;
struct aaa
{
int to,nx,f;
}edge[MxE];
inline void add_edge(int x,int y,int z)
{
edge[++edge_t]=(aaa){y,la[x],z},la[x]=edge_t;
edge[++edge_t]=(aaa){x,la[y],0},la[y]=edge_t;
}
inline bool bfs()
{
for(int i=0;i<=tot;++i)dis[i]=-1;
for(dis[S]=0,q.push(S);q.size();)
{
p=q.front(),q.pop();
for(int i=cur[p]=la[p],v;i;i=edge[i].nx)if(edge[i].f && !(~dis[v=edge[i].to]))dis[v]=dis[p]+1,q.push(v);
}
return dis[T]>=0;
}
inline int dfs(int x,int f)
{
if(x==T)return f;
int used=0,tmp;
for(int &i=cur[x],v;i;i=edge[i].nx)if(edge[i].f && dis[v=edge[i].to]==dis[x]+1)
{
tmp=dfs(v,min(edge[i].f,f-used)),edge[i].f-=tmp,edge[i^1].f+=tmp;
if((used+=tmp)==f)break;
}
return used;
}
inline int Dinic()
{
int maxflow=0;
while(bfs())maxflow+=dfs(S,inf);
return maxflow;
}
int main()
{
scanf("%d%d%d%d%d",&n,&m,&a,&b,&c),T=(++tot);
for(int i=1;i<=n;++i)
{
scanf("%s",s[i]+1);
for(int j=1;j<=m;++j)
{
br[i][j]=(++tot),add_edge(S,br[i][j],inf+a+(j==1? b:0)),add_edge(br[i][j],T,inf);
wr[i][j]=(++tot),add_edge(S,wr[i][j],inf),add_edge(wr[i][j],T,inf+a+(j==1? b:0));
bc[i][j]=(++tot),add_edge(S,bc[i][j],inf),add_edge(bc[i][j],T,inf+a+(i==1? b:0));
wc[i][j]=(++tot),add_edge(S,wc[i][j],inf+a+(i==1? b:0)),add_edge(wc[i][j],T,inf);
if(j>1)add_edge(br[i][j-1],br[i][j],b),add_edge(wr[i][j],wr[i][j-1],b);
if(i>1)add_edge(bc[i][j],bc[i-1][j],b),add_edge(wc[i-1][j],wc[i][j],b);
}
}
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)
{
if(s[i][j]=='#')
{
add_edge(wr[i][j],T,inf);
add_edge(S,wc[i][j],inf);
add_edge(br[i][j],bc[i][j],c);
}
else
{
add_edge(bc[i][j],br[i][j],inf);
add_edge(bc[i][j],wc[i][j],inf);
add_edge(wr[i][j],br[i][j],inf);
add_edge(wc[i][j],br[i][j],c);
add_edge(bc[i][j],wr[i][j],c);
}
}
return 0&printf("%d",Dinic()-inf*n*m*4);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3652kb
input:
3 3 1 2 3 .#. ### .#.
output:
10
result:
ok answer is '10'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 7 0 1 1 ###.### ###.###
output:
3
result:
ok answer is '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
5 5 1 4 4 ..#.. ..#.. ##.## ..#.. ..#..
output:
24
result:
ok answer is '24'
Test #4:
score: 0
Accepted
time: 13ms
memory: 3692kb
input:
7 24 1 10 10 ###...###..#####....###. .#...#...#.#....#..#...# .#..#......#....#.#..... .#..#......#####..#..... .#..#......#......#..... .#...#...#.#.......#...# ###...###..#........###.
output:
256
result:
ok answer is '256'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3620kb
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 ######################################## ######################################## ######################################## ######################################## ######################################## ######################################## #######################################...