QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#123666 | #1197. Draw in Straight Lines | Diu | WA | 1ms | 3744kb | C++14 | 2.0kb | 2023-07-13 10:45:11 | 2023-07-13 10:45:12 |
Judging History
answer
#include<bits/stdc++.h>
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;
const int N=1e5+10,Inf=1e8;
int T,n,m,a,b,c,s,t;
struct edge{
int v,w,nxt;
}e[N];
int hd[N],tot;
void add(int u,int v,int w){e[++tot]={v,w,hd[u]},hd[u]=tot;}
void Add(int u,int v,int w){add(u,v,w),add(v,u,0);}
int id(int k,int x,int y){return k*n*m+(x-1)*m+y;}
char ch[N];
int lev[N];
bool bfs(){
for(int i=1;i<=t;i++)lev[i]=-1;
lev[s]=1;queue<int> q;q.push(s);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].w&&lev[v]==-1){
lev[v]=lev[u]+1,q.push(v);
if(v==t)return 1;
}
}
}
return 0;
}
int dfs(int u,int in){
if(u==t)return in;
int out=0;
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].w&&lev[v]==lev[u]+1){
int use=dfs(v,min(e[i].w,in));
e[i].w-=use,out+=use;
e[i^1].w+=use,in-=use;
if(!in)break;
}
}
if(!out)lev[u]=-1;
return out;
}
int dinic(){
int ans=0;
while(bfs())ans+=dfs(s,Inf);
return ans;
}
signed main(){
// file("color");
scanf("%d",&T);
for(;T--;){
scanf("%d%d%d%d%d",&n,&m,&a,&b,&c);
tot=1;
s=n*m*4+1,t=s+1;
for(int i=1;i<=t;i++)hd[i]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
Add(s,id(0,i,j),a);
if(j<m)Add(id(0,i,j+1),id(0,i,j),b);
else Add(s,id(0,i,j),b);
Add(s,id(1,i,j),a);
if(i<n)Add(id(1,i+1,j),id(1,i,j),b);
else Add(s,id(1,i,j),b);
Add(id(2,i,j),t,a);
if(j<m)Add(id(2,i,j),id(2,i,j+1),b);
else Add(id(2,i,j),t,b);
Add(id(3,i,j),t,a);
if(i<n)Add(id(3,i,j),id(3,i+1,j),b);
else Add(id(3,i,j),t,b);
}
}
for(int i=1;i<=n;i++){
scanf("\n%s",ch+1);
for(int j=1;j<=m;j++){
if(ch[j]=='#'){
Add(id(0,i,j),id(3,i,j),c);
Add(s,id(1,i,j),Inf);
Add(id(2,i,j),t,Inf);
}else{
Add(id(1,i,j),id(0,i,j),c);
Add(id(3,i,j),id(2,i,j),c);
Add(id(3,i,j),id(0,i,j),Inf);
}
}
}
printf("%d\n",dinic());
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3744kb
input:
3 3 1 2 3 .#. ### .#.
output:
0 0 0
result:
wrong answer expected '10', found '0'