QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#525452 | #5668. Cell Nuclei Detection | QRQRQR | TL | 75ms | 196164kb | C++20 | 3.2kb | 2024-08-20 16:45:31 | 2024-08-20 16:45:31 |
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 int long long
#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) {}
};
int n, m;
Rect ground[50001];
int area[50001];
Rect detect[50001];
set<int> mp[2001][2001];
map<int, int> connect[100001];
bool vis[100001];
int S[100001];
bool dfs(int now) {
for (auto [nxt, v] : connect[now]) {
if (!vis[nxt]) {
vis[nxt] = true;
if (S[nxt] == -1 || dfs(S[nxt])) {
S[nxt] = now;
return true;
}
}
}
return false;
}
void sol() {
for (int i = 0; i < m; i++) {
auto [x1, y1, x2, y2] = ground[i];
area[i] = 0;
for (int x = x1; x < x2+1; x++) {
for (int y = y1; y < y2+1; y++) {
mp[x][y].insert(i);
area[i]++;
}
}
}
for (int i = 0; i < n; i++) {
auto [x1, y1, x2, y2] = detect[i];
map<int, int> cnt;
for (int x = x1; x < x2+1; x++) {
for (int y = y1; y < y2+1; y++) {
for (auto id : mp[x][y]) {
cnt[id]++;
}
}
}
for (auto [id, c] : cnt) {
//debug(id, c, area[id]);
if (c >= (area[id] + 1) / 2) {
connect[i][n+id] = 1;
connect[n+id][i] = 1;
}
}
}
fill(S, S+n+m, -1);
int ans = 0;
for (int i = 0; i < n+m; i++) {
memset(vis, 0, sizeof(vis));
if (dfs(i)) ans++;
}
cout << ans / 2 << '\n';
for (int i = 0; i < n+m; i++) {
connect[i] = map<int, int>();
}
for (int i = 0; i < 2001; i++) {
for (int j = 0; j < 2001; j++) {
mp[i][j] = set<int>();
}
}
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
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;
ground[i] = Rect(x1, y1, x2, y2);
}
for (int i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
detect[i] = Rect(x1, y1, x2, y2);
}
sol();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 75ms
memory: 196164kb
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: 75ms
memory: 196068kb
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: -100
Time Limit Exceeded
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 ...