QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376868 | #1197. Draw in Straight Lines | aqz180321 | Compile Error | / | / | C++14 | 2.6kb | 2024-04-04 17:54:47 | 2024-04-04 17:54:48 |
Judging History
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 * 1000];
ll head[N * 100], egtot = 1;
ll now[N * 100];
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 * 100];
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;
}
詳細信息
/tmp/ccELVoY8.o: in function `dinic(int, int)': answer.code:(.text+0x96): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccELVoY8.o /tmp/ccELVoY8.o: in function `BFS()': answer.code:(.text+0x1cb): relocation truncated to fit: R_X86_64_PC32 against symbol `s' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text+0x269): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text+0x2ea): relocation truncated to fit: R_X86_64_PC32 against symbol `t' defined in .bss section in /tmp/ccELVoY8.o /tmp/ccELVoY8.o: in function `main': answer.code:(.text.startup+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text.startup+0x28): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text.startup+0x37): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text.startup+0x46): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text.startup+0x55): relocation truncated to fit: R_X86_64_PC32 against symbol `c' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text.startup+0x63): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccELVoY8.o answer.code:(.text.startup+0x71): additional relocation overflows omitted from the output collect2: error: ld returned 1 exit status