QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217400#5114. Cells Coloringucup-team1001WA 0ms3992kbC++203.0kb2023-10-16 20:34:232023-10-16 20:34:23

Judging History

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

  • [2023-10-16 20:34:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3992kb
  • [2023-10-16 20:34:23]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define irep(i,l,r) for(int i = l; i <= r; ++i)

const int itinf = 1e9;
inline char rc(){
	char ch = getchar();
	while(1){
		if(ch == '*' || ch == '.')return ch;
		ch = getchar();
	}
}
inline ll read(){
	char ch = getchar();
	ll s = 0; bool w = 0;
	while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
	while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return w ? - s : s;
}

template<class T>
struct Flow {
    const int n;
    struct Edge {
        int to;
        T cap;
        Edge(int to, T cap) : to(to), cap(cap) {}
    };
    std::vector<Edge> e;
    std::vector<std::vector<int>> g;
    std::vector<int> cur, h;
    Flow(int n) : n(n), g(n) {}
    
    bool bfs(int s, int t) {
        h.assign(n, -1);
        std::queue<int> que;
        h[s] = 0;
        que.push(s);
        while (!que.empty()) {
            const int u = que.front();
            que.pop();
            for (int i : g[u]) {
                auto [v, c] = e[i];
                if (c > 0 && h[v] == -1) {
                    h[v] = h[u] + 1;
                    if (v == t) {
                        return true;
                    }
                    que.push(v);
                }
            }
        }
        return false;
    }
    
    T dfs(int u, int t, T f) {
        if (u == t) {
            return f;
        }
        auto r = f;
        for (int &i = cur[u]; i < int(g[u].size()); ++i) {
            const int j = g[u][i];
            auto [v, c] = e[j];
            if (c > 0 && h[v] == h[u] + 1) {
                auto a = dfs(v, t, std::min(r, c));
                e[j].cap -= a;
                e[j ^ 1].cap += a;
                r -= a;
                if (r == 0) {
                    return f;
                }
            }
        }
        return f - r;
    }
    void addEdge(int u, int v, T c) {
        g[u].push_back(e.size());
        e.emplace_back(v, c);
        g[v].push_back(e.size());
        e.emplace_back(u, 0);
    }
    T maxFlow(int s, int t) {
        T ans = 0;
        while (bfs(s, t)) {
            cur.assign(n, 0);
            ans += dfs(s, t, std::numeric_limits<T>::max());
        }
        return ans;
    }
};

int main(){
	int n = read(), m = read(), cnt = 0;
	ll c = read(), d = read();
	

	int S = n + m, T = n + m + 1;
	vector<array<int, 2>>eg;

	irep(i, 0, n - 1){
		irep(j, 0, m - 1){
			if(rc() == '.'){
				++ cnt;
				eg.push_back({i, j + n});
//				flow.addEdge(i,j + n,1);
			}
		}
	}
//	return 0;

	ll ans = std::numeric_limits<ll>::max();
	irep(k, 0, max(n, m) + 1){
		Flow<int>flow(n + m + 2);
		
		irep(j, 0, m -1 ){
			flow.addEdge(j + n, T, itinf);
		}
		irep(i, 0, n - 1){
			flow.addEdge(S, i, k);
		}
		for(auto [u, v] : eg)flow.addEdge(u, v, k);
		
		ans = min(ans ,1ll * (cnt - flow.maxFlow(S,T)) * d + 1ll * k * c);
		
	}
	printf("%lld", ans);
	return 0;
}

詳細信息

Test #1:

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

input:

3 4 2 1
.***
*..*
**..

output:

0

result:

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