QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#525674 | #5668. Cell Nuclei Detection | QRQRQR | AC ✓ | 595ms | 431628kb | C++20 | 5.3kb | 2024-08-20 20:14:13 | 2024-08-20 20:14:14 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
using std::cerr;
#define safe cerr << __PRETTY_FUNCTION__ << " Line " << __LINE__ << " safe\n"
#define debug(args...) qqbx(#args, args)
#define orange(args...) danb(#args, args)
template <typename ...T> void qqbx(const char *s, T ...args) {
int cnt = sizeof...(T);
((cerr << "\033[1;32m(" << s << ")=("), ...,
(cerr << args << (--cnt?", ":")\e[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
cerr << "\033[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L) cerr << (f++?", ":"") << *L;
cerr << " ]\033[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define orange(...) ((void)0)
#endif
#define F first
#define S second
#define pb push_back
#define ALL(x) begin(x), end(x)
#define lowbit(x) (x & (-x))
using namespace std;
using pii = pair<int, int>;
using ll = long long;
struct Rect {
int x1, y1, x2, y2;
Rect() {}
Rect(int _x1, int _y1, int _x2, int _y2) : x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
};
struct Dinic {
const int INF = 1<<30;
static const int MAXN = 50005 * 2;
struct Edge {
int u, v;
int cap, rest;
};
int n, m, s, t, d[MAXN], cur[MAXN];
vector<Edge> edges;
vector<int> G[MAXN];
void init() {
edges.clear();
for (int i = 0; i < MAXN; i++) {
G[i].clear();
}
}
void add_edge(int u, int v, int cap) {
edges.push_back({u, v, cap, cap});
edges.push_back({v, u, 0, 0});
m = edges.size();
G[u].push_back(m-2);
G[v].push_back(m-1);
}
bool bfs() {
memset(d, -1, sizeof(d));
queue<int> que;
que.push(s); d[s] = 0;
while (!que.empty()) {
int u = que.front(); que.pop();
for (int ei : G[u]) {
Edge &e = edges[ei];
if (d[e.v] < 0 && e.rest > 0) {
d[e.v] = d[u] + 1;
que.push(e.v);
}
}
}
return d[t] >= 0;
}
int dfs(int u, int a) {
if (u == t || a == 0) return a;
int flow = 0, f;
for (int &i = cur[u]; i < (int)G[u].size(); i++) {
Edge &e = edges[G[u][i]];
if (d[u] + 1 != d[e.v]) continue;
f = dfs(e.v, min(a, e.rest));
if (f > 0) {
e.rest -= f;
edges[G[u][i] ^ 1].rest += f;
flow += f;
a -= f;
if (a == 0) break;
}
}
return flow;
}
int maxflow(int s, int t) {
this->s = s, this->t = t;
int flow = 0, mf;
while (bfs()) {
memset(cur, 0, sizeof(cur));
while ((mf = dfs(s, INF))) {
flow += mf;
}
}
return flow;
}
};
int n, m;
Rect ground[50005];
int area[50005];
Rect detect[50005];
set<pair<pii, int>> mp[2005][2005];
set<int> connect[50005];
int intersect(Rect a, Rect b) {
int x1, y1, x2, y2;
x1 = max(a.x1, b.x1);
y1 = max(a.y1, b.y1);
x2 = min(a.x2, b.x2);
y2 = min(a.y2, b.y2);
if (x1 >= x2 || y1 >= y2) return 0;
return (x2 - x1) * (y2 - y1);
}
void sol() {
Dinic *flow = new Dinic();
flow->init();
for (int i = 0; i < 2000+1; i++) {
for (int j = 0; j < 2000+1; j++) {
mp[i][j] = set<pair<pii, int>>();
}
}
for (int i = 0; i < n; i++) connect[i] = set<int>();
for (int i = 0; i < m; i++) {
auto [x1, y1, x2, y2] = ground[i];
area[i] = 0;
mp[x1][y1].insert({{x2, y2}, i});
}
for (int i = 0; i < n; i++) {
auto [x1, y1, x2, y2] = detect[i];
for (int x = max(0, x1-4); x < min(2000, x1+4)+1; x++) {
for (int y = max(0, y1-4); y < min(2000, y1+4)+1; y++) {
for (auto [rxy, j] : mp[x][y]) {
auto [rx, ry] = rxy;
if (intersect(Rect(x, y, rx, ry), detect[i]) * 2 >= (rx - x) * (ry - y)) {
connect[i].insert(j);
}
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j : connect[i]) {
flow->add_edge(i, n+j, 1);
}
}
for (int i = 0; i < n; i++) {
flow->add_edge(n+m+1, i, 1);
}
for (int i = n; i < n+m; i++) {
flow->add_edge(i, n+m+2, 1);
}
ll ans = flow->maxflow(n+m+1, n+m+2);
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int tc = 1;
cin >> tc;
while (tc--) {
cin >> m >> n;
int x1, y1, x2, y2;
for (int i = 0; i < m; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
ground[i] = Rect(x1, y1, x2, y2);
}
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
detect[i] = Rect(x1, y1, x2, y2);
}
sol();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 76ms
memory: 205008kb
input:
3 2 2 1 1 3 3 3 3 5 5 2 2 4 4 4 4 6 6 2 3 1 1 3 3 3 3 5 5 1 3 3 5 2 1 4 5 3 1 5 3 3 3 1 1 2 2 2 2 3 3 3 3 4 4 1 1 3 3 2 2 4 4 3 3 5 5
output:
0 1 3
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 90ms
memory: 205520kb
input:
3 2 2 1 1 3 3 3 3 5 5 2 2 4 4 4 4 6 6 2 3 1 1 3 3 3 3 5 5 1 3 3 5 2 1 4 5 3 1 5 3 3 3 1 1 2 2 2 2 3 3 3 3 4 4 1 1 3 3 2 2 4 4 3 3 5 5
output:
0 1 3
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 359ms
memory: 310356kb
input:
5 50000 50000 0 0 4 4 4 0 8 4 8 0 12 4 12 0 16 4 16 0 20 4 20 0 24 4 24 0 28 4 28 0 32 4 32 0 36 4 36 0 40 4 40 0 44 4 44 0 48 4 48 0 52 4 52 0 56 4 56 0 60 4 60 0 64 4 64 0 68 4 68 0 72 4 72 0 76 4 76 0 80 4 80 0 84 4 84 0 88 4 88 0 92 4 92 0 96 4 96 0 100 4 100 0 104 4 104 0 108 4 108 0 112 4 112 ...
output:
50000 50000 0 50000 3150
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 395ms
memory: 296272kb
input:
5 50000 50000 0 0 1 1 1 0 2 1 2 0 3 1 3 0 4 1 4 0 5 1 5 0 6 1 6 0 7 1 7 0 8 1 8 0 9 1 9 0 10 1 10 0 11 1 11 0 12 1 12 0 13 1 13 0 14 1 14 0 15 1 15 0 16 1 16 0 17 1 17 0 18 1 18 0 19 1 19 0 20 1 20 0 21 1 21 0 22 1 22 0 23 1 23 0 24 1 24 0 25 1 25 0 26 1 26 0 27 1 27 0 28 1 28 0 29 1 29 0 30 1 30 0 ...
output:
50000 25050 12500 16000 8000
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 310ms
memory: 252072kb
input:
5 50000 50000 0 0 2 4 4 0 7 1 8 0 10 1 12 0 15 3 16 0 19 1 20 0 22 2 24 0 26 4 28 0 30 4 32 0 36 3 36 0 40 1 40 0 44 1 44 0 47 2 48 0 49 3 52 0 54 1 56 0 59 4 60 0 64 3 64 0 68 3 68 0 70 1 72 0 76 4 76 0 80 3 80 0 84 4 84 0 87 2 88 0 90 1 92 0 94 4 96 0 98 1 100 0 104 1 104 0 107 2 108 0 110 4 112 0...
output:
10594 10779 10618 10381 10779
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 595ms
memory: 431628kb
input:
5 50000 50000 0 0 4 4 1 0 5 4 2 0 6 4 3 0 7 4 4 0 8 4 5 0 9 4 6 0 10 4 7 0 11 4 8 0 12 4 9 0 13 4 10 0 14 4 11 0 15 4 12 0 16 4 13 0 17 4 14 0 18 4 15 0 19 4 16 0 20 4 17 0 21 4 18 0 22 4 19 0 23 4 20 0 24 4 21 0 25 4 22 0 26 4 23 0 27 4 24 0 28 4 25 0 29 4 26 0 30 4 27 0 31 4 28 0 32 4 29 0 33 4 30...
output:
50000 50000 50000 50000 49600
result:
ok 5 lines
Test #7:
score: 0
Accepted
time: 36ms
memory: 198012kb
input:
1 4 4 1 1 3 3 2 1 4 3 1 2 3 4 2 2 4 4 2 1 4 3 3 2 5 4 1 2 3 4 2 3 4 5
output:
3
result:
ok single line: '3'