QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#119991 | #5668. Cell Nuclei Detection | hos_lyric | WA | 140ms | 114292kb | C++14 | 4.6kb | 2023-07-06 10:03:43 | 2023-07-06 10:03:44 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
namespace bm {
constexpr int LIM_N0 = 50'010;
constexpr int LIM_N1 = 50'010;
constexpr int LIM_M = 10'000'010;
int n0, n1, m, as[LIM_M], bs[LIM_M];
int to[LIM_N0], fr[LIM_N1], tof;
int pt[LIM_N0 + 2], zu[LIM_M], used[LIM_N0], lev[LIM_N0], que[LIM_N0], *qb, *qe;
void init(int n0_, int n1_) {
n0 = n0_; n1 = n1_; m = 0;
}
int ae(int u, int v) {
as[m] = u; bs[m] = v; return m++;
}
int augment(int u) {
used[u] = tof;
for (int j = pt[u]; j < pt[u + 1]; ++j) {
const int v = zu[j];
const int w = fr[v];
if (!~w || (used[w] != tof && lev[u] < lev[w] && augment(w))) {
to[u] = v; fr[v] = u; return 1;
}
}
return 0;
}
int run() {
memset(pt, 0, (n0 + 2) * sizeof(int));
for (int i = 0; i < m; ++i) ++pt[as[i] + 2];
for (int u = 2; u <= n0; ++u) pt[u + 1] += pt[u];
for (int i = 0; i < m; ++i) zu[pt[as[i] + 1]++] = bs[i];
memset(to, ~0, n0 * sizeof(int));
memset(fr, ~0, n1 * sizeof(int));
memset(used, ~0, n0 * sizeof(int));
for (tof = 0; ; ) {
qb = qe = que; memset(lev, ~0, n0 * sizeof(int));
for (int u = 0; u < n0; ++u) if (!~to[u]) lev[*qe++ = u] = 0;
for (; qb != qe; ) {
const int u = *qb++;
for (int j = pt[u]; j < pt[u + 1]; ++j) {
const int w = fr[zu[j]];
if (~w && !~lev[w]) lev[*qe++ = w] = lev[u] + 1;
}
}
int f = 0;
for (int u = 0; u < n0; ++u) if (!~to[u]) f += augment(u);
if (!f) return tof;
tof += f;
}
}
// s: true, t: false (s: reachable from unmatched left)
// vertex cover: (0: false, 0: true)
// independent set: (0: true, 1: false)
bool side0[LIM_N0], side1[LIM_N1];
void dfs(int u) {
if (!side0[u]) {
side0[u] = true;
for (int j = pt[u]; j < pt[u + 1]; ++j) {
const int v = zu[j];
if (!side1[v]) {
side1[v] = true;
const int w = fr[v];
if (~w) dfs(w);
}
}
}
}
void minCut() {
memset(side0, 0, n0 * sizeof(bool));
memset(side1, 0, n1 * sizeof(bool));
for (int u = 0; u < n0; ++u) if (!~to[u]) dfs(u);
}
} // namespace bm
int M, N;
vector<int> X0, Y0, X1, Y1;
constexpr int L = 2010;
vector<int> vss[L][L];
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d%d", &M, &N);
X0.resize(M + N);
Y0.resize(M + N);
X1.resize(M + N);
Y1.resize(M + N);
for (int u = 0; u < M + N; ++u) {
scanf("%d%d%d%d", &X0[u], &Y0[u], &X1[u], &Y1[u]);
if (X0[u] > X1[u]) swap(X0[u], X1[u]);
if (Y0[u] > Y1[u]) swap(Y0[u], Y1[u]);
}
for (int x = 0; x < L; ++x) for (int y = 0; y < L; ++y) {
vss[x][y].clear();
}
for (int v = M; v < M + N; ++v) {
vss[X0[v]][Y0[v]].push_back(v);
}
bm::init(M, N);
for (int u = 0; u < M; ++u) {
for (int x = max(X0[u] - 3, 0); x <= X0[u]; ++x)
for (int y = max(Y0[u] - 3, 0); y <= Y0[u]; ++y)
{
for (const int v : vss[x][y]) {
const int dg =
max(min(X1[u], X1[v]) - max(X0[u], X0[v]), 0) *
max(min(Y1[u], Y1[v]) - max(Y0[u], Y0[v]), 0);
const int g = (X1[u] - X0[u]) * (Y1[u] - Y0[u]);
// cerr<<u<<" "<<v<<" "<<dg<<" "<<g<<endl;
if (2 * dg >= g) {
bm::ae(u, v - M);
}
}
}
}
const int ans = bm::run();
printf("%d\n", ans);
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 22ms
memory: 105560kb
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: 35ms
memory: 105048kb
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
Wrong Answer
time: 140ms
memory: 114292kb
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 49750 0 50000 3150
result:
wrong answer 2nd lines differ - expected: '50000', found: '49750'