Submission #2630244

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

typedef vector<vector<int>> Graph; // G[u] = {v,...}

bool augment(const Graph& g, int src, vector<int>& matchTo, vector<bool>& visited) {
    if (src < 0) return true;
    for (int dst : g[src]) if (!visited[dst]) {
        visited[dst] = true;
        if (augment(g, matchTo[dst], matchTo, visited)) {
            matchTo[src] = dst;
            matchTo[dst] = src;
            return true;
        }
    }
    return false;
}

int bipartiteMatching(const Graph& g, int L, vector<ii>& matching) {
    const int n = g.size();
    vector<int> matchTo(n, -1);
    int match = 0;
    rep(u, L) {
        vector<bool> visited(n);
        if (augment(g, u, matchTo, visited)) ++match;
    }
    rep(u, L) {
        if (matchTo[u] >= 0) { // make explicit matching
            //matching.push_back( ii(u, matchTo[u]) );
        }
    }
    return match;
}

int bip(int N, vector<ii>& arc){
    Graph g(N*2);
    for (ii a: arc){
        g[a.first].pb(N+a.second);
        g[N+a.second].pb(a.first);
    }
    vector<ii> matching;
    int match = bipartiteMatching(g, N, matching);
    return match;
}


int solve(int N, vi& a, vi& b, vi& c, vi& d) {
    vector<ii> arc;
    arc.reserve(N*N);
    rep(i,N) rep(j,N) {
        if (i == j) continue;
        if (a[i] < c[j] && b[i] < d[j]) arc.pb(ii(i,j));
    }
    return bip(N,arc);
}

int main() {
    int N; cin >>N;
    vi a(N), b(N), c(N), d(N);
    rep(i,N){
        cin >> a[i] >> b[i];
    }
    rep(i,N){
        cin >> c[i] >> d[i];
    }
    cout << solve(N,a,b,c,d) << endl;
    return 0;
}

Submission Info

Submission Time
Task C - 2D Plane 2N Points
User naoya_t
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2683 Byte
Status
Exec Time 1 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example_0, example_1, example_2, example_3, example_4
All 0 / 400 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 1 ms 256 KB
example_1 1 ms 256 KB
example_2 1 ms 256 KB
example_3 1 ms 256 KB
example_4 1 ms 256 KB
line_0 1 ms 256 KB
line_1 1 ms 256 KB
line_2 1 ms 256 KB
line_3 1 ms 256 KB
maxrand_0 1 ms 256 KB
maxrand_1 1 ms 256 KB
maxrand_2 1 ms 256 KB
maxrand_3 1 ms 256 KB
maxrand_4 1 ms 256 KB
rand_0 1 ms 256 KB
rand_1 1 ms 256 KB
rand_2 1 ms 256 KB