Submission #3769401


Source Code Expand

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

int main(void){
    int n, inf = 1000, ans = 0;
    cin >> n;
    int a[1105], b[1105], c[1105], d[1105], e[1205], f[1205], g[1205], h[1205];
    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) { 
            if (c[g[i]] > d[h[i]]) {
                bool x = false;
                for (int j = i - 1; j >= 0; j--) {
                    if (e[j] >= 0 && b[f[j]] < d[h[i]]) {
                        ans++;
                        a[e[j]] = b[f[j]] = inf;
                        x = true;
                        break;
                    }
                }
                if (!x) {
                for (int j = i - 1; j >= 0; j--) {
                    if (f[j] >= 0 && a[e[j]] < c[g[i]]) {
                        ans++;
                        c[g[j]] = d[h[j]] = inf;
                        break;
                    }
                }
                }
            }
            else if (c[g[i]] < d[h[i]]) {
                for (int j = i - 1; j >= 0; j--) {
                    if (f[j] >= 0 && a[e[j]] < c[g[i]]) {
                        ans++;
                        c[g[j]] = d[h[j]] = inf;
                        break;
                    }
                }
                for (int j = i - 1; j >= 0; j--) {
                    if (e[j] >= 0 && b[f[j]] < d[h[i]]) {
                        ans++;
                        a[e[j]] = b[f[j]] = inf;
                        break;
                    }
                }
            }
            else {
                for (int j = i - 1; j >= 0; j--) {
                    if (f[j] >= 0 && a[e[j]] < c[g[i]]) {
                        ans++;
                        c[g[j]] = d[h[j]] = inf;
                        break;
                    }
                }
            }
        } 
        else if (g[i] >= 0) {
            for (int j = i - 1; j >= 0; j--) {
                if (e[j] >= 0 && b[f[j]] < d[h[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[e[j]] < c[g[i]]) {
                    ans++;
                    c[f[j]] = d[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 3052 Byte
Status WA
Exec Time 2 ms
Memory 256 KB

Judge Result

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