QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632911#5114. Cells ColoringDiverbeeWA 175ms8532kbC++143.3kb2024-10-12 14:10:552024-10-12 14:11:01

Judging History

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

  • [2024-10-12 14:11:01]
  • 评测
  • 测评结果:WA
  • 用时:175ms
  • 内存:8532kb
  • [2024-10-12 14:10:55]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5+10;

struct MF {
    struct edge {
        int v, nxt, cap, flow;
    } e[N];

    int fir[N], cnt = 0;

    int n, S, T;
    ll maxflow = 0;
    int dep[N], cur[N];

    void init(int x) {
        memset(fir, -1, sizeof fir);
        maxflow = 0;
        cnt = 0;
    }

    void addedge(int u, int v, int w) {
        e[cnt] = {v, fir[u], w, 0};
        fir[u] = cnt++;
        e[cnt] = {u, fir[v], 0, 0};
        fir[v] = cnt++;
    }

    bool bfs() {
        queue<int> q;
        memset(dep, 0, sizeof(int) * (n + 1));

        dep[S] = 1;
        q.push(S);
        while (q.size()) {
            int u = q.front();
            q.pop();
            for (int i = fir[u]; ~i; i = e[i].nxt) {
                int v = e[i].v;
                if ((!dep[v]) && (e[i].cap > e[i].flow)) {
                    dep[v] = dep[u] + 1;
                    q.push(v);
                }
            }
        }
        return dep[T];
    }

    int dfs(int u, int flow) {
        if ((u == T) || (!flow)) return flow;

        int ret = 0;
        for (int& i = cur[u]; ~i; i = e[i].nxt) {
            int v = e[i].v, d;
            if ((dep[v] == dep[u] + 1) &&
                (d = dfs(v, min(flow - ret, e[i].cap - e[i].flow)))) {
                ret += d;
                e[i].flow += d;
                e[i ^ 1].flow -= d;
                if (ret == flow) return ret;
            }
        }
        return ret;
    }

    void dinic() {
        while (bfs()) {
            memcpy(cur, fir, sizeof(int) * (n + 1));
            maxflow += dfs(S, INF);
        }
    }
} mf;

int mp[300][300];

int n, m;
ll c,d;
void dis(){
    for(int i = 1; i <=n ;++i){
        for(int j = 1; j<=m;++j){
            cout<<mp[i][j]<<' ';
        }cout<<'\n';
    }cout<<'\n';
}

int main() {

    cin >> n >> m>>c>>d;
    ll cst = d*n*m;
    for(int i=1;i<=n;++i){
        for(int j = 1; j<=m;++j){
            char c;cin>>c;
            if(c=='*'){
                mp[i][j] = 1;
                cst -=d;
            }
        }
    }

    ll ans =INF;
    ans = min(ans,cst);

    for(int i = 1 ; i<=500;++i){
        cst+=c;

        mf.init(n*m+m+n+2);
        mf.n = n*m+m+n+2;
        mf.S = n*m+m+n+1;
        mf.T = n*m+m+n+2;

        for(int j = 1; j<=n;++j){
            mf.addedge(n*m+j,mf.T,1);
        }
        for(int j = 1; j<=m;++j){
            mf.addedge(mf.S,n*m+n+j,1);
        }

        for(int j = 1; j<=n;++j){
            for(int k = 1; k<=m;++k){
                if(!mp[j][k]){
                    mf.addedge(n*m+n+k,m*(j-1)+k,1);
                    mf.addedge(m*(j-1)+k,n*m+j,1);
                }
            }
        }

        mf.dinic();
        cst -= d*mf.maxflow;

        for(int i = 0 ; i<mf.cnt;i+=2){
            if(mf.e[i].flow){
                int u = mf.e[i].v;
                if(u>m*n&&u<=m*n+n){
                    u = mf.e[i^1].v;
                    int x = (u-1)/m+1;
                    int y = (u-1)%m+1;
                    mp[x][y] = 1;
                }
            }
        }
        ans = min(ans,cst);
        if(mf.maxflow==0)break;
    }


    cout<<ans;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 175ms
memory: 8532kb

input:

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

output:

110064368508

result:

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