QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88270 | #1197. Draw in Straight Lines | Unique_Hanpi | WA | 2ms | 3768kb | C++14 | 2.6kb | 2023-03-15 19:07:30 | 2023-03-15 19:07:34 |
Judging History
answer
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 45;
const int Mod = 998244353;
const int INF = 0x3f3f3f3f;
const int S = 0, T = N * N * 4 - 1;
int head[N * N * 4], edge_num = 1;
struct edge {
int nxt, to, w;
} G[N * N * N];
inline void add(int u, int v, int w) {
// printf("|%d %d %d|\n", u, v, w);
G[++edge_num] = (edge) { head[u], v, w };
head[u] = edge_num;
G[++edge_num] = (edge) { head[v], u, 0 };
head[v] = edge_num;
}
int cur[N * N * 4], dep[N * N * 4];
inline bool bfs() {
memcpy(cur, head, sizeof(cur));
memset(dep, 0, sizeof(dep));
queue<int> Q;
Q.push(S);
dep[S] = 1;
while (!Q.empty()) {
int top = Q.front();
Q.pop();
for (int i = head[top]; i; i = G[i].nxt) {
int v = G[i].to;
if (dep[v] || !G[i].w) continue;
dep[v] = dep[top] + 1;
if (v == T) return 1;
Q.push(v);
}
}
return 0;
}
int dfs(int x, int f) {
if (x == T) return f;
for (int &i = cur[x]; i; i = G[i].nxt) {
int v = G[i].to;
if (dep[v] != dep[x] + 1 || !G[i].w) continue;
int d = dfs(v, min(f, G[i].w));
if (d) {
G[i].w -= d;
G[i ^ 1].w += d;
return d;
} else dep[v] = 0;
}
return 0;
}
int n, m, a, b, c;
char s[N];
inline int id(int x, int y, int c) {
return 4 * ((m + 1) * x + y) - c;
}
int main() {
scanf("%d%d%d%d%d", &n, &m, &a, &b, &c);
for (int i = 1; i <= n; i++) add(id(i, 0, 0), T, INF), add(S, id(i, 0, 2), INF);
for (int i = 1; i <= m; i++) add(S, id(0, i, 1), INF), add(id(0, i, 3), T, INF);
for (int i = 1; i <= n; i++) {
scanf(" %s", s + 1);
for (int j = 1; j <= m; j++) {
if (s[j] == '#') {
add(S, id(i, j, 2), a);
add(id(i, j, 3), T, a);
add(S, id(i, j, 1), INF);
add(id(i, j, 0), T, INF);
add(id(i, j, 2), id(i, j, 3), c);
} else {
add(S, id(i, j, 2), a);
add(id(i, j, 3), T, a);
add(S, id(i, j, 1), a);
add(id(i, j, 0), T, a);
add(id(i, j, 1), id(i, j, 2), c);
add(id(i, j, 3), id(i, j, 0), c);
}
add(id(i, j - 1, 2), id(i, j, 2), b);
add(id(i - 1, j, 1), id(i, j, 1), b);
add(id(i, j, 3), id(i - 1, j, 3), b);
add(id(i, j, 0), id(i, j - 1, 0), b);
}
}
int ans = 0;
while (bfs()) while (int d = dfs(S, INF)) ans += d;
printf("%d", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3560kb
input:
3 3 1 2 3 .#. ### .#.
output:
10
result:
ok answer is '10'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
2 7 0 1 1 ###.### ###.###
output:
3
result:
ok answer is '3'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3728kb
input:
5 5 1 4 4 ..#.. ..#.. ##.## ..#.. ..#..
output:
24
result:
ok answer is '24'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3768kb
input:
7 24 1 10 10 ###...###..#####....###. .#...#...#.#....#..#...# .#..#......#....#.#..... .#..#......#####..#..... .#..#......#......#..... .#...#...#.#.......#...# ###...###..#........###.
output:
256
result:
ok answer is '256'
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 3576kb
input:
5 5 0 3 2 ..#.. ..#.. ##.## ..#.. ..#..
output:
10
result:
wrong answer expected '11', found '10'