QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335141#1197. Draw in Straight LinesEasonLiangWA 1ms3940kbC++144.1kb2024-02-22 19:35:362024-02-22 19:35:36

Judging History

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

  • [2024-02-22 19:35:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3940kb
  • [2024-02-22 19:35:36]
  • 提交

answer

#include <bits/stdc++.h>
#define FileIO_(file) \
    freopen (file ".in", "r", stdin); \
    freopen (file ".out", "w", stdout);

using namespace std;

template<typename Tp>
inline void chmin (Tp &x, const Tp &y) { if (y < x) x = y; }
template<typename Tp>
inline void chmax (Tp &x, const Tp &y) { if (x < y) x = y; }

typedef double dbl;
typedef long long ll;
typedef long double ldb;

void init () {}

const int maxnm = 4e1 + 2;
int n, m, a, b, c;

namespace Dinic {

const int inf = 0x3f3f3f3f;
const int maxvcnt = 4 * maxnm * maxnm;
const int maxecnt = 2 * 11 * maxnm * maxnm;
int s, t, ecnt, h[maxvcnt], cur[maxvcnt], dis[maxvcnt];

struct Edge {
    int w, to, nxt;
} e[maxecnt];

void init (int s, int t) {
    Dinic::s = s; Dinic::t = t; ecnt = 0;
    memset (h, ~0, sizeof (h));
}

void addEdge (int u, int v, int w) {
    e[ecnt] = {w, v, h[u]}; h[u] = ecnt++;
}

void link (int u, int v, int w) {
    addEdge (u, v, w); addEdge (v, u, 0);
}

bool bfs () {
    memcpy (cur, h, sizeof (cur));
    memset (dis, ~0, sizeof (dis));
    queue<int> q; q.emplace (s); dis[s] = 0;

    while (!q.empty ()) {
        int u = q.front (); q.pop ();

        for (int i = h[u]; ~i; i = e[i].nxt) {
            if (e[i].w && !~dis[e[i].to]) {
                dis[e[i].to] = dis[u] + 1;
                q.emplace (e[i].to);
            }
        }
    }

    return ~dis[t];
}

int dfs (int u, int flow) {
    if (u == t) return flow;

    int res = 0;

    for (int &i = cur[u]; ~i; i = e[i].nxt) {
        int v = e[i].to, &w = e[i].w;
        if (!w || dis[u] + 1 != dis[v]) continue;
        int ext = dfs (v, min (w, flow - res));
        w -= ext; e[i ^ 1].w += ext;
        if ((res += ext) == flow) break;
    }

    return res;
}

int work () {
    int res = 0;

    while (bfs ())
        res += dfs (s, inf);
    
    return res;
}

} // namespace Dinic

int getid (int x, int y) {
    return (x - 1) * (m + 1) + y;
}

enum Type { hb, vb, hw, vw };

int getid (int x, int y, Type tp) {
    return getid (x, y) << 2 | tp;
}

void solve () {
    scanf ("%d%d%d%d%d", &n, &m, &a, &b, &c);

    Dinic::init (1, 2);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            static int ch; while (!isgraph (ch = getchar ()));
            Dinic::link (getid (i, j, hb), Dinic::t, a);
            Dinic::link (Dinic::s, getid (i, j, vb), a);
            Dinic::link (Dinic::s, getid (i, j, hw), a);
            Dinic::link (getid (i, j, vw), Dinic::t, a);
            Dinic::link (getid (i, j, hb), getid (i, j + 1, hb), b);
            Dinic::link (getid (i + 1, j, vb), getid (i, j, vb), b);
            Dinic::link (getid (i + 1, j, hw), getid (i, j, hw), b);
            Dinic::link (getid (i, j, vw), getid (i, j + 1, vw), b);
            if (ch == '#') {
                Dinic::link (getid (i, j, vb), getid (i, j, hb), c);
                Dinic::link (Dinic::s, getid (i, j, hw), Dinic::inf);
                Dinic::link (getid (i, j, vw), Dinic::t, Dinic::inf);
            } else {
                Dinic::link (getid (i, j, hb), getid (i, j, vw), c);
                Dinic::link (getid (i, j, hw), getid (i, j, vb), c);
                Dinic::link (getid (i, j, hb), getid (i, j, vb), Dinic::inf);
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        Dinic::link (getid (i, m + 1, hb), Dinic::t, Dinic::inf);
        Dinic::link (Dinic::s, getid (i, m + 1, vb), Dinic::inf);
        Dinic::link (Dinic::s, getid (i, m + 1, hw), Dinic::inf);
        Dinic::link (getid (i, m + 1, vw), Dinic::t, Dinic::inf);
    }

    for (int i = 1; i <= m; ++i) {
        Dinic::link (getid (n + 1, i, hb), Dinic::t, Dinic::inf);
        Dinic::link (Dinic::s, getid (n + 1, i, vb), Dinic::inf);
        Dinic::link (Dinic::s, getid (n + 1, i, hw), Dinic::inf);
        Dinic::link (getid (n + 1, i, vw), Dinic::t, Dinic::inf);
    }

    printf ("%d\n", Dinic::work ());
}

int main () {
//	#ifndef LSY
//	FileIO_("");
//	#endif
    int t = 1; init ();
//	scanf ("%d", &t);
    while (t--) solve ();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3940kb

input:

3 3 1 2 3
.#.
###
.#.

output:

10

result:

ok answer is '10'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3864kb

input:

2 7 0 1 1
###.###
###.###

output:

4

result:

wrong answer expected '3', found '4'