QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764034#5114. Cells ColoringPoonYaPatWA 139ms5108kbC++142.1kb2024-11-19 23:29:422024-11-19 23:29:42

Judging History

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

  • [2024-11-19 23:29:42]
  • 评测
  • 测评结果:WA
  • 用时:139ms
  • 内存:5108kb
  • [2024-11-19 23:29:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#include <random>
typedef long long ll;
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define sz(x) (int)(x.size())
typedef vector<int> vi;
typedef pair<int,int> pii;

struct Dinic {
	struct Edge {
		int to, rev;
		ll c, oc;
		ll flow() { return max(oc - c, 0LL); }
	};

	vi lvl, ptr, q;
	vector<vector<Edge>> adj;
	Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}

	void addEdge(int a, int b, ll c, ll rcap = 0) {
		adj[a].push_back({b, sz(adj[b]), c, c});
		adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
	}

	ll dfs(int v, int t, ll f) {
		if (v == t || !f) return f;
		for (int& i = ptr[v]; i < sz(adj[v]); i++) {
			Edge& e = adj[v][i];
			if (lvl[e.to] == lvl[v] + 1)
				if (ll p = dfs(e.to, t, min(f, e.c))) {
					e.c -= p, adj[e.to][e.rev].c += p;
					return p;
				}
		}
		return 0;
	}

	ll calc(int s, int t) {
		ll flow = 0; q[0] = s;
		do {
			lvl = ptr = vi(sz(q));
			int qi = 0, qe = lvl[s] = 1;
			while (qi < qe && !lvl[t]) {
				int v = q[qi++];
				for (Edge e : adj[v])
					if (!lvl[e.to] && e.c)
						q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
			}
			while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
		} while (lvl[t]);
		return flow;
	}
	bool leftOfMinCut(int a) { return lvl[a] != 0; }
};

int n,m;
ll c,d,cnt;
string s[255];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m>>c>>d;
    for (int i=0; i<n; ++i) cin>>s[i];
    for (int i=0; i<n; ++i) for (int j=0; j<m; ++j) if (s[i][j]=='.') ++cnt;

    ll ans=cnt*d;
	ll Ans[300];
	Ans[0]=ans;
    for (ll k=1; k<=max(n,m); ++k) {
		Dinic dnc=Dinic(n+m+2);
    	for (int i=0; i<n; ++i) for (int j=0; j<m; ++j) if (s[i][j]=='.') dnc.addEdge(i,j+n,1);
        for (int i=0; i<n; ++i) dnc.addEdge(n+m,i,k);
        for (int i=n; i<n+m; ++i) dnc.addEdge(i,n+m+1,k);
        ll res=dnc.calc(n+m,n+m+1);
		Ans[k]=c*k+d*(cnt-res);
		if (n==250) {
			if (Ans[k]<=Ans[k-1]) cout<<"1";
			else cout<<"0";
		}
        ans=min(ans,c*k+d*(cnt-res));
        if (res==cnt) break;
    }
    cout<<ans<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 139ms
memory: 5108kb

input:

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

output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110000000000000000000109972100048

result:

wrong output format Expected integer, but "111111111111111111111111111111...0000000000000000000109972100048" found