답안 #217240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217240 2020-03-29T09:51:57 Z kartel Matching (COCI20_matching) C++14
5 / 110
32 ms 47360 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +1000005
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

int x[N], y[N], n, i, mk[N], j, fst, sd;
vector <int> g[N], G[N];

int main()
{
//    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
//    in("data.in");
//    out("data.out");
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }
    for (fst = 0; fst < n; fst++)
      for (sd = 0; sd < n; sd++)
        if (fst != sd && (x[fst] == x[sd] || y[fst] == y[sd]))
    {
        vector <pair <int, int> > ver, hor;
        for (i = 0; i < n; i++)
            g[x[i]].clear(), G[y[i]].clear(), mk[i] = 0;
        mk[fst] = mk[sd] = 1;

        if (x[fst] == x[sd])
        {
            hor.pb({fst, sd});
        }
        else ver.pb({fst, sd});

        for (i = 0; i < n; i++)
            if (!mk[i])
        {
            g[x[i]].pb(i);
            G[y[i]].pb(i);
        }

        for (i = 0; i < n; i++)
        {
            if (mk[i]) continue;
            if (!mk[g[x[i]][1]] && g[x[i]][1] != i)
            {
                int j = g[x[i]][1];
                hor.pb({i, j});
                mk[j] = mk[i] = 1;
            }
            else if (!mk[G[y[i]][1]] && G[y[i]][1] != i)
            {
                int j = G[y[i]][1];
                ver.pb({i, j});
                mk[j] = mk[i] = 1;
            }
        }

        bool f = 1;

        for (i = 0; i < hor.size(); i++)
            {
                int dx = min(x[hor[i].F], x[hor[i].S]);

                int dy = min(y[hor[i].F], y[hor[i].S]);
                int uy = max(y[hor[i].F], y[hor[i].S]);

                for (j = 0; j < ver.size(); j++)
                {
                    int lx = min(x[ver[j].F], x[ver[j].S]);
                    int rx = max(x[ver[j].F], x[ver[j].S]);

                    int ly = min(y[ver[j].F], y[ver[j].S]);

                    if (dx >= lx && dx <= rx && dy < ly && uy > ly) f = 0;
                }
            }
        if (!f) continue;

        cout << "DA" << el;
        for (auto x : hor) cout << x.F + 1 << " " << x.S + 1 << el;
        for (auto x : ver) cout << x.F + 1 << " " << x.S + 1 << el;
        return 0;
    }
    cout << "NE";
}

Compilation message

matching.cpp: In function 'int main()':
matching.cpp:83:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < hor.size(); i++)
                     ~~^~~~~~~~~~~~
matching.cpp:90:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (j = 0; j < ver.size(); j++)
                             ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 32 ms 47360 KB Output is correct
5 Correct 32 ms 47360 KB Output is correct
6 Incorrect 32 ms 47360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 32 ms 47360 KB Output is correct
5 Correct 32 ms 47360 KB Output is correct
6 Incorrect 32 ms 47360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 32 ms 47360 KB Output is correct
5 Correct 32 ms 47360 KB Output is correct
6 Incorrect 32 ms 47360 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 47360 KB Output is correct
2 Correct 32 ms 47352 KB Output is correct
3 Correct 32 ms 47360 KB Output is correct
4 Correct 32 ms 47360 KB Output is correct
5 Correct 32 ms 47360 KB Output is correct
6 Incorrect 32 ms 47360 KB Output isn't correct
7 Halted 0 ms 0 KB -