QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329002 | #1197. Draw in Straight Lines | yllcm | WA | 0ms | 14284kb | C++14 | 3.5kb | 2024-02-16 11:43:58 | 2024-02-16 11:43:58 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
int x = 0; bool op = false;
char c = getchar();
while(!isdigit(c))op |= (c == '-'), c = getchar();
while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 55;
const int INF = 1e9;
int n, m, A, B, C, tot;
int a[N][N], id[N][N][4];
const int M = 1e6 + 10;
int S, T, etot = 1;
int head[M], to[M], nxt[M], flow[M];
void addedge(int u, int v, int w) {
to[++etot] = v; flow[etot] = w;
nxt[etot] = head[u]; head[u] = etot;
return ;
}
void add(int u, int v, int w) {
addedge(u, v, w); addedge(v, u, 0);
return ;
}
int lev[M], cur[M];
bool bfs() {
for(int i = 0; i <= T; i++)
cur[i] = head[i], lev[i] = 0;
queue<int> q; q.push(S); lev[S] = 1;
while(q.empty() == false) {
int u = q.front(); q.pop();
for(int i = head[u]; i; i = nxt[i]) {
if(flow[i] && lev[to[i]] == 0) {
lev[to[i]] = lev[u] + 1;
if(to[i] == T)return true;
q.push(to[i]);
}
}
}
return false;
}
int dinic(int u, int w) {
if(u == T)return w;
int v = w;
for(int i = cur[u]; i && v; i = nxt[i]) {
cur[u] = i;
if(flow[i] == 0 || lev[to[i]] != lev[u] + 1)continue;
int inc = dinic(to[i], min(v, flow[i]));
if(inc == 0)lev[to[i]] = 0;
v -= inc; flow[i] -= inc; flow[i ^ 1] += inc;
}
return w - v;
}
int vis[N];
void dfs(int u) {
if(vis[u])return ;
vis[u] = true;
for(int i = head[u]; i; i = nxt[i])
if(flow[i])dfs(to[i]);
return ;
}
void solve() {
n = read(); m = read();
A = read(); B = read(); C = read();
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%1d", &a[i][j]);
tot = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
for(int k = 0; k < 4; k++)
id[i][j][k] = ++tot;
S = 0; T = tot + 1; etot = 1;
for(int i = 0; i <= T; i++)head[i] = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
add(S, id[i][j][0], A);
add(id[i][j][1], T, A);
add(id[i][j][2], T, A);
add(S, id[i][j][3], A);
if(j < m) {
add(id[i][j + 1][0], id[i][j][0], B);
add(id[i][j][2], id[i][j + 1][2], B);
}
else {
add(S, id[i][j][0], B);
add(id[i][j][2], T, B);
}
if(i < n) {
add(id[i][j][1], id[i + 1][j][1], B);
add(id[i + 1][j][3], id[i][j][3], B);
}
else {
add(id[i][j][1], T, B);
add(S, id[i][j][3], B);
}
if(a[i][j] == '#') {
add(id[i][j][0], id[i][j][1], C);
add(id[i][j][2], T, INF);
add(S, id[i][j][3], INF);
}
else {
add(id[i][j][3], id[i][j][0], C);
add(id[i][j][1], id[i][j][2], C);
add(id[i][j][1], id[i][j][0], INF);
}
}
}
int tmp = 0, ans = 0;
while(bfs())while(tmp = dinic(S, INF))ans += tmp;
// dfs(S);
// cout << head[S] << endl;
// for(int i = head[S]; i; i = nxt[i])cout << to[i] << ' ' << flow[i] << endl;
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= m; j++) {
// for(int k = 0; k < 4; k++)
// printf("%d", vis[id[i][j][k]]);
// putchar('\n');
// }
// }
printf("%d\n", ans);
return ;
}
int main() {
int test = 1;
while(test--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 14284kb
input:
3 3 1 2 3 .#. ### .#.
output:
0
result:
wrong answer expected '10', found '0'