QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#119992#5668. Cell Nuclei Detectionhos_lyricAC ✓480ms121112kbC++144.6kb2023-07-06 10:05:112023-07-06 10:05:12

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 10:05:12]
  • 评测
  • 测评结果:AC
  • 用时:480ms
  • 内存:121112kb
  • [2023-07-06 10:05:11]
  • 提交

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] - 4, 0); x <= X0[u] + 4; ++x)
      for (int y = max(Y0[u] - 4, 0); y <= Y0[u] + 4; ++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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 25ms
memory: 104748kb

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: 38ms
memory: 105808kb

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: 258ms
memory: 118372kb

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: 175ms
memory: 121112kb

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: 181ms
memory: 107948kb

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: 480ms
memory: 115028kb

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: 8ms
memory: 105920kb

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'