Submission #2411212


Source Code Expand

#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <functional>

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;
  Edge(size_t src, size_t dst, Weight cost=1):
    src(src), dst(dst), cost(cost)
  {}
};

template <class Weight>
using Graph=std::vector<std::vector<Edge<Weight>>>;

template <class Weight>
constexpr Weight inf=(Weight(1)<<(8*sizeof (Weight)-3));

template <class Weight>
size_t bipartite_match(const Graph<Weight> &g, size_t mid) { 
  std::vector<size_t> pair(g.size(), -1);
  std::function<bool (size_t, std::vector<bool> &)> augment;
  augment = [&](size_t u, std::vector<bool> &visited) {
    if (u+1 == 0) return true;

    for (const Edge<Weight> &e: g[u]) {
      if (visited[e.dst]) continue;
      visited[e.dst] = true;
      if (augment(pair[e.dst], visited)) {
        pair[e.src] = e.dst;
        pair[e.dst] = e.src;
        return true;
      }
    }
    return false;
  };

  size_t match=0;
  for (size_t i=0; i<mid; ++i) {
    std::vector<bool> visited(g.size());
    if (augment(i, visited))
      ++match;
  }
  return match;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> a(N), b(N);
  for (size_t i=0; i<N; ++i)
    scanf("%d %d", &a[i], &b[i]);

  std::vector<int> c(N), d(N);
  for (size_t i=0; i<N; ++i)
    scanf("%d %d", &c[i], &d[i]);

  Graph<int> g(2*N);
  for (size_t i=0; i<N; ++i)
    for (size_t j=0; j<N; ++j)
      if (a[i] < c[j] && b[i] < d[j]) {
        g[i].emplace_back(i, N+j);
        g[N+j].emplace_back(N+j, i);
      }

  printf("%zu\n", bipartite_match(g, N));
}

Submission Info

Submission Time
Task C - 2D Plane 2N Points
User rsk0315
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1675 Byte
Status AC
Exec Time 2 ms
Memory 424 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:52:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%zu", &N);
                   ^
./Main.cpp:56:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &a[i], &b[i]);
                                 ^
./Main.cpp:60:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &c[i], &d[i]);
                                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 17
Set Name Test Cases
Sample example_0, example_1, example_2, example_3, example_4
All example_0, example_1, example_2, example_3, example_4, line_0, line_1, line_2, line_3, maxrand_0, maxrand_1, maxrand_2, maxrand_3, maxrand_4, rand_0, rand_1, rand_2
Case Name Status Exec Time Memory
example_0 AC 1 ms 256 KB
example_1 AC 1 ms 256 KB
example_2 AC 1 ms 256 KB
example_3 AC 1 ms 256 KB
example_4 AC 1 ms 256 KB
line_0 AC 1 ms 384 KB
line_1 AC 1 ms 256 KB
line_2 AC 1 ms 256 KB
line_3 AC 1 ms 256 KB
maxrand_0 AC 1 ms 384 KB
maxrand_1 AC 1 ms 384 KB
maxrand_2 AC 1 ms 384 KB
maxrand_3 AC 2 ms 424 KB
maxrand_4 AC 1 ms 384 KB
rand_0 AC 1 ms 384 KB
rand_1 AC 1 ms 256 KB
rand_2 AC 1 ms 384 KB