Submission #3771299


Source Code Expand

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(void){
    int n, inf = 300, ans = 0;
    cin >> n;
    int a[305], b[305], c[305], d[305], e[305], f[305], g[305], h[305];
    for (int i = 0; i < 2 * n; i++) {
        e[i] = f[i] = g[i] = h[i] = -1;
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        e[a[i]] = f[b[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i] >> d[i];
        g[c[i]] = h[d[i]] = i;
    }
    
    for (int i = 2 * n - 1; i >= 0; i--) {
        if (g[i] >= 0 && h[i] >= 0) { 
            bool x = false;
            if (c[g[i]] > d[h[i]]) {
                for (int j = i - 1; j >= 0; j--) {
                    if (e[j] >= 0 && b[e[j]] < d[g[i]]) {
                        ans++;
                        a[e[j]] = b[e[j]] = inf;
                        x = true;
                        break;
                    }
                }
                if (!x) {
                    for (int j = i - 1; j >= 0; j--) {
                        if (f[j] >= 0 && a[f[j]] < c[h[i]]) {
                            ans++;
                            a[f[j]] = b[f[j]] = inf;
                            break;
                        }
                    }
                }
            }
            else if (c[g[i]] < d[h[i]]) {
                for (int j = i - 1; j >= 0; j--) {
                    if (f[j] >= 0 && a[f[j]] < c[h[i]]) {
                        ans++;
                        a[f[j]] = b[f[j]] = inf;
                        x = true;
                        break;
                    }
                }
                if (!x) {
                    for (int j = i - 1; j >= 0; j--) {
                        if (e[j] >= 0 && b[e[j]] < d[g[i]]) {
                            ans++;
                            a[e[j]] = b[e[j]] = inf;
                            break;
                        }
                    }
                }
            }
            else {
                for (int j = i - 1; j >= 0; j--) {
                    if (f[j] >= 0 && a[f[j]] < c[h[i]]) {
                        ans++;
                        a[f[j]] = b[f[j]] = inf;
                        break;
                    }
                }
            }
        } 
        else if (g[i] >= 0) {
            for (int j = i - 1; j >= 0; j--) {
                if (e[j] >= 0 && b[e[j]] < d[g[i]]) {
                    ans++;
                    a[e[j]] = b[e[j]] = inf;
                    break;
                }
            }
        }
        else if (h[i] >= 0) {
            for (int j = i - 1; j >= 0; j--) {
                if (f[j] >= 0 && a[f[j]] < c[h[i]]) {
                    ans++;
                    a[f[j]] = b[f[j]] = inf;
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;
    
//    for (int i = 0; i < n; i++) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
//    for (int i = 0; i < 2*n; i++) cout << e[i] << " " << f[i] << " " << g[i] << " " << h[i] << endl;
}

Submission Info

Submission Time
Task C - 2D Plane 2N Points
User ast210
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3180 Byte
Status WA
Exec Time 2 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 5
AC × 10
WA × 7
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 256 KB
line_1 AC 1 ms 256 KB
line_2 AC 1 ms 256 KB
line_3 AC 1 ms 256 KB
maxrand_0 WA 1 ms 256 KB
maxrand_1 WA 1 ms 256 KB
maxrand_2 WA 1 ms 256 KB
maxrand_3 AC 2 ms 384 KB
maxrand_4 WA 1 ms 256 KB
rand_0 WA 1 ms 256 KB
rand_1 WA 1 ms 256 KB
rand_2 WA 1 ms 256 KB