QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132863#1197. Draw in Straight LinesWatwareWA 1ms3892kbC++173.1kb2023-07-31 20:53:502023-07-31 20:53:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-31 20:53:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3892kb
  • [2023-07-31 20:53:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
constexpr int N = 10100, M = 101000, C = 60;
constexpr i64 OMEGA = INT_MAX / 100, INF = LONG_LONG_MAX / 10000;

int to[M], nxt[M], head[N], tot = 2;
int dis[N], cur[N], cnt = 1;
i64 val[M];
int wx[C][C], wy_[C][C], bx_[C][C], by[C][C];

inline void add(int u, int v, i64 w) {
    // printf("add %d %d %lld\n", u, v, w);
    to[tot] = v, val[tot] = w, nxt[tot] = head[u], head[u] = tot++;
    to[tot] = u, val[tot] = 0, nxt[tot] = head[v], head[v] = tot++;
}
inline bool bfs(int s, int t) {
    static queue<int> q;
    memset(dis, 0x3f, sizeof(dis));
    dis[s] = 0, q.push(s);
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i = head[p]; i; i = nxt[i])
            if (val[i] && dis[to[i]] > dis[p] + 1) dis[to[i]] = dis[p] + 1, q.push(to[i]);
    }
    return dis[t] != dis[0];
}
i64 dfs(int n, i64 fl, int t) {
    if (n == t) return fl;
    i64 lf = fl;
    for (int &i = cur[n]; i; i = nxt[i])
        if (val[i] && dis[to[i]] == dis[n] + 1) {
            i64 d = dfs(to[i], min(lf, val[i]), t);
            val[i] -= d, val[i ^ 1] += d, lf -= d;
            if (!lf) return fl;
        }
    return fl - lf;
}
i64 dinic(int s, int t) {
    i64 res = 0;
    while (bfs(s, t)) memcpy(cur, head, sizeof(cur)), res += dfs(s, INF, t); // printf("!!! %lld\n", res);
    return res;
}

int n, m, a, b, c;

int main() {
    scanf("%d%d%d%d%d", &n, &m, &a, &b, &c);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) wx[i][j] = cnt++, wy_[i][j] = cnt++, bx_[i][j] = cnt++, by[i][j] = cnt++;
    int s = cnt++, t = cnt++;
    // printf("!!!\n");
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            char c;
            scanf(" %c", &c);
            add(s, wx[i][j], a + OMEGA);
            add(wx[i][j], t, OMEGA);

            add(s, wy_[i][j], OMEGA);
            add(wy_[i][j], t, a + OMEGA);
            
            add(s, bx_[i][j], OMEGA);
            add(bx_[i][j], t, a + OMEGA);
            
            add(s, by[i][j], a + OMEGA);
            add(by[i][j], t, OMEGA);

            if (i == 1) {
                add(s, wx[i][j], b);
                add(bx_[i][j], t, b);
            } else {
                add(wx[i - 1][j], wx[i][j], b);
                add(bx_[i][j], bx_[i - 1][j], b);
            }

            if (j == 1) {
                add(wy_[i][j], t, b);
                add(s, by[i][j], b);
            } else {
                add(by[i][j - 1], by[i][j], b);
                add(wy_[i][j], wy_[i][j - 1], b);
            }

            if (c == '.') {
                add(wx[i][j], by[i][j], c);
                add(bx_[i][j], wy_[i][j], c);
                add(bx_[i][j], by[i][j], INF);
            } else {
                add(s, wx[i][j], INF);
                add(wy_[i][j], t, INF);
                add(by[i][j], bx_[i][j], c);
            }
        }
    i64 ans = dinic(s, t);
    // printf("%lld %lld\n", OMEGA, ans);
    ans -= OMEGA * n * m * 4;
    printf("%lld\n", ans);
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

10

result:

ok answer is '10'

Test #2:

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

input:

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

output:

3

result:

ok answer is '3'

Test #3:

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

input:

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

output:

24

result:

ok answer is '24'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3892kb

input:

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

output:

264

result:

wrong answer expected '256', found '264'