QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217447#5114. Cells Coloringucup-team1001WA 16ms4396kbC++203.2kb2023-10-16 21:12:212023-10-16 21:12:21

Judging History

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

  • [2023-10-16 21:12:21]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:4396kb
  • [2023-10-16 21:12:21]
  • 提交

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) {
   // 	cout << e.size() << ' ' << u << ' ' << v << ' ' << c << endl;
        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();
	Flow<ll>flow(n + m + 2);
	int S = n + m, T = n + m + 1;
	vector<array<int, 2>>eg;
	irep(i, 0, n - 1){
		flow.addEdge(S, i, 0);
	}
	irep(i, 0, m - 1){
		flow.addEdge(i + n, T, 1e7);
	}
	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();
	int res = 0;
	irep(k, 0, max(n, m)){

//		for(auto [u, v] : eg)flow.addEdge(u, v, 1);
//		cout << flow.maxFlow(S,T) << endl;
		res += flow.maxFlow(S,T);
		ans = min(ans ,1ll * (cnt - res) * d + 1ll * k * c);
		
		for(int i = 0; i < n; ++ i){
			flow.e[i * 2].cap ++;
		//	cerr << flow.e[i * 2].to << ' ' << flow.e[i * 2].cap << endl;
		}
	}
	printf("%lld", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4036kb

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 16ms
memory: 4396kb

input:

250 250 965680874 9042302
..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.***
....**.*******.*.******...

output:

109628492572

result:

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