QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#629098 | #9224. Express Eviction | ucup-team3215 | WA | 1ms | 4252kb | C++23 | 2.8kb | 2024-10-11 03:48:54 | 2024-10-11 03:48:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
constexpr ll INF = 1e9 + 7;
#define rep(i, l, r) for(int i =l;i < r;++i)
#define sz(c) (int)c.size()
struct Dinic {
struct Edge {
int to, rev;
ll c, oc;
ll flow() { return max(oc - c, 0LL); } // if you need flows
};
vi lvl, ptr, q;
vector<vector<Edge>> adj;
Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
void addEdge(int a, int b, ll c, ll rcap = 0) {
adj[a].push_back({b, sz(adj[b]), c, c});
adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
}
ll dfs(int v, int t, ll f) {
if (v == t || !f) return f;
for (int &i = ptr[v]; i < sz(adj[v]); i++) {
Edge &e = adj[v][i];
if (lvl[e.to] == lvl[v] + 1)
if (ll p = dfs(e.to, t, min(f, e.c))) {
e.c -= p, adj[e.to][e.rev].c += p;
return p;
}
}
return 0;
}
ll calc(int s, int t) {
ll flow = 0;
q[0] = s;
rep(L, 0, 31) do { // 'int L=30' maybe faster for random data
lvl = ptr = vi(sz(q));
int qi = 0, qe = lvl[s] = 1;
while (qi < qe && !lvl[t]) {
int v = q[qi++];
for (Edge e: adj[v])
if (!lvl[e.to] && e.c >> (30 - L))
q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
}
while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
} while (lvl[t]);
return flow;
}
bool leftOfMinCut(int a) { return lvl[a] != 0; }
};
int main() {
cin.tie(0)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
int N = n * m * 2 + 2;
int st = N - 2, en = N - 1;
int cur = 0;
Dinic sol(N);
vector<vector<int>> who(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
char c;
cin >> c;
who[i][j] = cur;
sol.addEdge(cur, cur + 1, c == '#');
if (!j || i == n - 1)sol.addEdge(st, cur, INF);
if (!i || j == m - 1)sol.addEdge(cur + 1, en, INF);
cur += 2;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
for (int dx = -2; dx <= 2; ++dx) {
for (int dy = -2; dy <= 2; ++dy) {
if (abs(dx) + abs(dy) > 3 || abs(dx) + abs(dy) == 0)continue;
int ni = i + dx, nj = j + dy;
if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
sol.addEdge(who[i][j] + 1, who[ni][nj], INF);
}
}
}
}
}
cout << sol.calc(st,en);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4252kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
10
result:
wrong answer 1st numbers differ - expected: '11', found: '10'