답안 #223393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223393 2020-04-15T08:38:07 Z tqbfjotld Matching (COCI20_matching) C++14
5 / 110
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

bool done[45];
int u[45],r[45];
int connect[45];
bool toret = false;
int N;
vector<pair<int,pair<int,int> > >c1;
vector<pair<int,pair<int,int> > >c2;
int X[45],Y[45];

void iterate(int n){
    if (n==N){
        printf("DA\n");
        for (int x = 0; x<n; x++){
            if (connect[x]!=-1){
                printf("%d %d\n",x+1,connect[x]+1);
            }
        }
        toret = true;
        return;
    }

    if (u[n]!=-1){
        bool can = true;
        for (auto x : c2){
            if (X[n]<=x.second.second && X[n]>=x.second.first && x.first<=max(Y[n],Y[u[n]]) && x.first>=min(Y[n],Y[u[n]])){
                can = false;
                break;
            }
        }
        if (can && !done[u[n]]){
            connect[n] = u[n];
            done[n] = true;
            done[u[n]] = true;
            int t = n+1;
            while (done[t]) t++;
            c1.push_back({X[n],{min(Y[n],Y[u[n]]),max(Y[n],Y[u[n]])}});
            iterate(t);
            c1.pop_back();
            connect[n] = -1;
            if (toret) return;
            done[n] = false;
            done[u[n]] = false;
        }
    }
    if (r[n]!=-1){
        bool can = true;
        for (auto x : c1){
            if (Y[n]<=x.second.second && Y[n]>=x.second.first && x.first<=max(X[n],X[u[n]]) && x.first>=min(X[n],X[u[n]])){
                can = false;
                break;
            }
        }
        if (can && !done[r[n]]){
            connect[n] = r[n];
            done[n] = true;
            done[r[n]] = true;
            int t = n+1;
            while (done[t]) t++;
            c2.push_back({Y[n],{min(X[n],X[u[n]]),max(X[n],X[u[n]])}});
            iterate(t);
            c2.pop_back();
            if (toret) return;
            connect[n] = -1;
            done[n] = false;
            done[r[n]] = false;
        }
    }

}

int main(){
    memset(r,-1,sizeof(r));
    memset(u,-1,sizeof(u));
    memset(connect,-1,sizeof(connect));
    int n;
    scanf("%d",&n);
    N=n;
    vector<pair<pair<int,int>,int> >v;
    vector<pair<pair<int,int>,int> > v2;
    for (int x = 0; x<n; x++){
        int a,b;
        scanf("%d%d",&a,&b);
        v.push_back({{a,b},x});
        v2.push_back({{b,a},x});
        X[x] = a;
        Y[x] = b;
    }
    sort(v.begin(),v.end());
    sort(v2.begin(),v2.end());
    for (int x = 1; x<n; x++){
        if (v[x].first.first==v[x-1].first.first){
            int t1 = min(v[x].second,v[x-1].second);
            int t2 = max(v[x].second,v[x-1].second);
            u[t1] = t2;
        }
    }
    for (int x = 1; x<n; x++){
        if (v2[x].first.first==v2[x-1].first.first){
            int t1 = min(v2[x].second,v2[x-1].second);
            int t2 = max(v2[x].second,v2[x-1].second);
            r[t1] = t2;
        }
    }
    iterate(0);
    if (toret) return 0;
    printf("NE");
}

Compilation message

matching.cpp: In function 'int main()':
matching.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
matching.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 4 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 4 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 4 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 4 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -