QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#583824#9224. Express EvictionBerryPieWA 0ms23160kbC++202.7kb2024-09-22 22:53:432024-09-22 22:53:44

Judging History

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

  • [2024-09-22 22:53:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:23160kb
  • [2024-09-22 22:53:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

struct Edge{
    int u, v, nxt, cap, flow;
    Edge(int u = 0, int v = 0, int nxt = 0, int cap = 0, int flow = 0):
        u(u), v(v), nxt(nxt), cap(cap), flow(flow){}
};

const int MAXN = 50+5;
const int MAX = 5000+5;
const int inf = 1e9;
int n, m, cnt, tot, s, t;
int a[MAXN][MAXN], id[MAXN][MAXN][2];
int head[MAX], d[MAX], cur[MAX], vis[MAX];
Edge G[MAX*200];

void add_edge(int from, int to, int cap){
    G[++cnt] = Edge(from, to, head[from], cap, 0);  head[from] = cnt;
    G[++cnt] = Edge(to, from, head[to], 0, 0);  head[to] = cnt;
}
int bfs(){
    for(int i = 1; i <= tot; i++) vis[i] = 0;
    queue<int> que;
    que.push(s);
    d[s] = 0;
    vis[s] = true;
    while(!que.empty()){
        int u = que.front();  que.pop();
        for(int e = head[u]; e; e = G[e].nxt){
            int v = G[e].v;
            if(!vis[v] && G[e].cap > G[e].flow){
                vis[v] = true;
                d[v] = d[u] + 1;
                que.push(v);
            }
        }
    }
    return vis[t];
}
int dfs(int u, int a){
	if(u == t || a == 0)  return a;
	int flow = 0, f;
	for(int &e = cur[u]; e; e = G[e].nxt){
		int v = G[e].v;
		if(d[v] == d[u]+1 && (f = dfs(v, min(a, G[e].cap - G[e].flow))) > 0){
			G[e].flow += f;
			G[e^1].flow -= f;
			flow += f;
			a -= f;
			if(a == 0)  break;
		}
	}
	return flow;
}

int maxflow(){
    int flow = 0;
    while(bfs()){
        for(int i = 1; i <= tot; i++) cur[i] = head[i];
        flow += dfs(s, inf);
    }
    return flow;
}

int main(){
    cin >> n >> m;
    s = ++tot;
    t = ++tot;
    for(int i = 1; i <= n; i++){
        string s;
        cin >> s;
        s = ' ' + s;
        for(int j = 1; j <= m; j++){
            a[i][j] = s[j] == '#';
            id[i][j][0] = ++tot;
            id[i][j][1] = ++tot;
        }
    }
    cnt = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j]){
                add_edge(id[i][j][0], id[i][j][1], 1);
                if(j == 1 || i == n){
                    add_edge(s, id[i][j][0], inf);
                }
                if(j == m || i == 1){
                    add_edge(id[i][j][1], t, inf);
                }
                for(int i1 = -2; i1 <= 2; i1++){
                    for(int j1 = -2; j1 <= 2; j1++){
                        if(i1 == 0 && j1 == 0) continue;
                        if(i+i1 < 1 || i+i1 > n || j+j1 < 1 || j+j1 > m || !a[i-i1][j+j1]) continue;
                        add_edge(id[i][j][1], id[i+i1][j+j1][0], inf);
                    }
                }
            }
        }
    }
    cout << maxflow() << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 23160kb

input:

4 6
.##...
.#....
##....
....#.

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'