답안 #423971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423971 2021-06-11T14:51:58 Z lyc 카멜레온의 사랑 (JOI20_chameleon) C++14
20 / 100
60 ms 332 KB
#include "chameleon.h"
#include <vector>

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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef pair<int,int> ii;

namespace {
    int N;
    vector<int> F, M;
    bool paired[1001];

    int findedge(int x, vector<int> v, int l, int r) {
        int lo = l-1, hi = r+1;
        while (hi-lo > 1) {
            int mid = (lo+hi)/2;

            vector<int> qv = {x};
            FOR(i,l,mid) qv.push_back(v[i]);
            int col = Query(qv);

            if (col != mid-(l-1)+1) hi = mid;
            else lo = mid;
        }
        return hi;
    }

    bool pointto(int x, vector<int> v, int y) {
        vector<int> qv = {x};
        for (int& a : v) if (a != y) qv.push_back(a);
        int col = Query(qv);
        //TRACE(x _ y _ col);
        //for (int& a : qv) { cout << a << ' '; } cout << endl << endl;
        return col == SZ(v)-2;
    }
}  // namespace


void Solve(int _N) {
    N = _N;
    F.assign(N,0);
    M.assign(N,0);
    iota(ALL(F),1);
    iota(ALL(M),N+1);
    memset(paired,0,sizeof paired);

    vector<ii> ans, ans2;
    for (int& x : F) {
        vector<int> pos;
        vector<ii> cur;

        int prv = -1;
        FOR(i,0,2){
            int p = findedge(x,M,prv+1,N-1);
            if (p >= N) break;
            prv = p;
            pos.push_back(M[p]);
        }

        if (SZ(pos) == 1) {
            ans.push_back(ii(x,pos[0]));
            paired[x] = paired[pos[0]] = 1;

        } else {
            for (int& y : pos) {
                if (!paired[y] && !pointto(x,M,y)) cur.push_back(ii(x,y));
            }

            if (SZ(cur) == 1) {
                ans.push_back(ii(x,cur[0].second));
                paired[x] = paired[cur[0].second] = 1;
            } else {
                for (auto& a : cur) ans2.push_back(a);
            }
        }
    }

    //cout << "ans" << endl; for (auto& x : ans) { cout << x.first _ x.second << endl; } cout << endl;
    //cout << "ans2" << endl; for (auto& x : ans2) { cout << x.first _ x.second << endl; } cout << endl;

    for (int& x : M) if (!paired[x]) {
        for (auto& p : ans2) if (x == p.second) {
            if (!pointto(x,F,p.first)) ans.push_back(p);
        }
    }

    //cout << "ans" << endl; for (auto& x : ans) { cout << x.first _ x.second << endl; } cout << endl;

    for (auto& x : ans) {
        Answer(x.first, x.second);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Incorrect 49 ms 332 KB Wrong Answer [6]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Incorrect 0 ms 200 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 55 ms 308 KB Output is correct
4 Correct 54 ms 316 KB Output is correct
5 Correct 54 ms 320 KB Output is correct
6 Correct 58 ms 308 KB Output is correct
7 Correct 57 ms 316 KB Output is correct
8 Correct 60 ms 320 KB Output is correct
9 Correct 55 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Incorrect 49 ms 332 KB Wrong Answer [6]
4 Halted 0 ms 0 KB -