QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74612#1197. Draw in Straight Lines18MichaelWA 2ms3716kbC++142.3kb2023-02-02 23:21:002023-02-02 23:21:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-02 23:21:01]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3716kb
  • [2023-02-02 23:21:00]
  • 提交

answer

//Test
#include<bits/stdc++.h>
using namespace std;
#define N 45
#define maxV N*N*4
#define maxE N*N*30
#define oo 0x3f3f3f3f
struct Edge{
    int nex,to,len;
}edge[maxE];
queue<int>q;
int n,m,V,E,a,b,c,ans,br[N][N],bc[N][N],wr[N][N],wc[N][N],head[maxV],work[maxV],d[maxV];
char s[N][N];
void add(int x,int y,int z){
    edge[E]=Edge{head[x],y,z};
    head[x]=E++;
    if (E&1)add(y,x,0);
}
bool bfs(){
    memset(d,oo,sizeof(d));
    d[0]=0,q.push(0);
    while (!q.empty()){
        int k=q.front();
        q.pop();
        for(int i=head[k];i!=-1;i=edge[i].nex)
            if ((edge[i].len)&&(d[edge[i].to]==oo)){
                d[edge[i].to]=d[k]+1;
                q.push(edge[i].to);
            }
    }
    return d[V]!=oo;
}
int dfs(int k,int s){
    if (k==V)return s;
    int ans=0;
    for(int &i=head[k];i!=-1;i=edge[i].nex)
        if ((edge[i].len)&&(d[edge[i].to]==d[k]+1)){
            int p=dfs(edge[i].to,min(s,edge[i].len));
            edge[i].len-=p,edge[i^1].len+=p,s-=p,ans+=p;
            if (!s)return ans;
        }
    return ans;
}
int main(){
    scanf("%d%d%d%d%d",&n,&m,&a,&b,&c);
    for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            br[i][j]=++V,bc[i][j]=++V;
            wr[i][j]=++V,wc[i][j]=++V;
        }
    V++;
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            add(0,br[i][j],a),add(0,wc[i][j],a);
            add(bc[i][j],V,a),add(wr[i][j],V,a);
            //add(wr[i][j],br[i][j],oo);
            //add(bc[i][j],wc[i][j],oo);
            if (s[i][j]=='#'){
                add(wr[i][j],V,oo),add(0,wc[i][j],oo);
                add(br[i][j],bc[i][j],c);
            }
            else{
                //add(bc[i][j],br[i][j],oo);
                add(wc[i][j],br[i][j],c);
                add(bc[i][j],wr[i][j],c);
            }
            if (j==1)add(0,br[i][j],b),add(wr[i][j],V,b);
            else add(br[i][j-1],br[i][j],b),add(wr[i][j],wr[i][j-1],b);
            if (i==1)add(bc[i][j],V,b),add(0,wc[i][j],b);
            else add(bc[i][j],bc[i-1][j],b),add(wc[i-1][j],wc[i][j],b);
        }
    memcpy(work,head,sizeof(head));
    while (bfs()){
        ans+=dfs(0,oo);
        memcpy(head,work,sizeof(head));
    }
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

10

result:

ok answer is '10'

Test #2:

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

input:

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

output:

3

result:

ok answer is '3'

Test #3:

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

input:

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

output:

24

result:

ok answer is '24'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

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

output:

256

result:

ok answer is '256'

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3676kb

input:

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

output:

10

result:

wrong answer expected '11', found '10'