QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376867#1197. Draw in Straight Linesaqz180321RE 1ms7768kbC++142.6kb2024-04-04 17:53:582024-04-04 17:53:59

Judging History

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

  • [2024-04-04 17:53:59]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7768kb
  • [2024-04-04 17:53:58]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>

typedef int ll;
const ll N = 500;
const ll M = 500;
const ll inf = 0x3f3f3f3f;
ll n, m, a, b, c, s, t, cnt, ans;
char ch;
ll bh[N][M], bs[N][M], wh[N][M], ws[N][M];
struct edge {
    ll to, nxt, w;
} eg[N * M * 100];
ll head[N * 10], egtot = 1;
ll now[N * 10];

void add (ll u, ll v, ll w) {
    eg[++egtot].to = v;
    eg[egtot].nxt = head[u];
    eg[egtot].w = w;
    head[u] = egtot;

    eg[++egtot].to = u;
    eg[egtot].nxt = head[v];
    eg[egtot].w = 0;
    head[v] = egtot;
}

ll d[N * 10];

bool BFS () {
     memset(d, 0, sizeof(d));
	std::queue < ll > q;
	q.push(s);
	d[s] = 1;
    now[s] = head[s];
	while (!q.empty()) {
		ll x = q.front();
		q.pop();
		for (ll i = head[x]; i; i = eg[i].nxt) {
			if (!eg[i].w) continue;
			ll to = eg[i].to;
			if (d[to]) continue;
			d[to] = d[x] + 1;
			now[to] = head[to];
			q.push(to);
			 if (to == t) return true;
		}
	}
	return false;
}

ll dinic (ll x, ll flow) {
	if (x == t) return flow;
	ll res = flow;
	for (ll i = now[x]; i; i = eg[i].nxt) {
		now[x] = i;
		if (!eg[i].w) continue;
		ll to = eg[i].to;
		if (d[to] != d[x] + 1) continue;
		ll k = dinic (to, std::min(res, eg[i].w));
		res -= k;
		eg[i].w -= k;
		eg[i ^ 1].w += k; 
	}
	return flow - res;
}

int main() {
//    freopen("in.in", "r", stdin);
//    freopen("out.out", "w", stdout);
    std::cin >> n >> m >> a >> b >> c;
    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= m; j++)
            bh[i][j] = ++cnt, bs[i][j] = ++cnt, wh[i][j] = ++cnt, ws[i][j] = ++cnt;
    s = ++cnt, t = ++cnt;
    for (ll i = 1; i <= n; i++)
        for (ll j = 1; j <= m; j++) {
            std::cin >> ch;
            add(s, bh[i][j], a);
            if (j + 1 <= m) add(bh[i][j + 1], bh[i][j], b);
            else add(s, bh[i][j], b);
            add(bs[i][j], t, a);
            if (j + 1 <= m) add(bs[i][j], bs[i][j + 1], b);
            else add(bs[i][j], t, b);
            add(wh[i][j], t, a);
            if (i + 1 <= n) add(wh[i][j], wh[i + 1][j], b);
            else add(wh[i][j], t, b);
            add(s, ws[i][j], a);
            if (i + 1 <= n) add(ws[i + 1][j], ws[i][j], b);
            else add(s, ws[i][j], b);
            if (ch == '.') {
                add(bs[i][j], wh[i][j], c); add(bh[i][j], ws[i][j], c);
                add(bs[i][j], ws[i][j], inf);
            } else {
                add(ws[i][j], bs[i][j], c);
                add(s, bh[i][j], inf); add(wh[i][j], t, inf);
            }
        }
    while (BFS()) ans += dinic(s, inf);
    std::cout << ans;
    return 0;
}

详细

Test #1:

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

input:

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

output:

10

result:

ok answer is '10'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7680kb

input:

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

output:

3

result:

ok answer is '3'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7736kb

input:

5 5 1 4 4
..#..
..#..
##.##
..#..
..#..

output:

24

result:

ok answer is '24'

Test #4:

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

input:

7 24 1 10 10
###...###..#####....###.
.#...#...#.#....#..#...#
.#..#......#....#.#.....
.#..#......#####..#.....
.#..#......#......#.....
.#...#...#.#.......#...#
###...###..#........###.

output:

256

result:

ok answer is '256'

Test #5:

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

input:

5 5 0 3 2
..#..
..#..
##.##
..#..
..#..

output:

11

result:

ok answer is '11'

Test #6:

score: -100
Runtime Error

input:

40 40 40 40 40
########################################
########################################
########################################
########################################
########################################
########################################
#######################################...

output:


result: