Submission #1291988

#TimeUsernameProblemLanguageResultExecution timeMemory
1291988serkanrashidChameleon's Love (JOI20_chameleon)C++17
40 / 100
33 ms472 KiB
#include "chameleon.h"
#include <bits/stdc++.h>


using namespace std;

//int Query(const std::vector<int> &p)
//void Answer(int a, int b)

const int MAXN = 1024;

int n;
vector<int>g[MAXN];
bool vis[MAXN];


/*
4
0 0 0 0 1 1 1 1
1 2 3 4 1 2 3 4
6 7 8 5 4 3 2 1
*/
/*
4
1 0 1 0 0 1 1 0
4 4 1 2 1 2 3 3
4 3 8 7 6 5 2 1
*/

int ch[MAXN];
int in[MAXN],ou[MAXN];
vector<int>p;

vector<int> subred(int l, int r)
{
    vector<int>res;
    for(int i = l; i <= r; i++) res.push_back(i);
    return res;
}

int bin_s(int i, pair<int,int> bef)
{
    int l = n+1;
    int r = 2*n;
    int mid;

    while(l <= r)
    {
        mid = (l+r)/2;
        p.clear();
        for(int j = n+1; j <= mid; j++) if(j != bef.first && j != bef.second) p.push_back(ch[j]);
        p.push_back(ch[i]);

        if(Query(p) <= p.size()-1) r = mid-1;
        else l = mid+1;
    }
    return l;
}

void SOLVE4(int i)
{
    //cout << "yeya" << endl;
    p.clear();
    for(int j = n+1; j <= 2*n; j++) p.push_back(ch[j]);
    p.push_back(ch[i]);

    int gr = 3;
    if(Query(p) == p.size() - 1) gr = 1;

    pair<int,int>bef = {0,-1};
    for(int j = 0; j < gr; j++)
    {
        //cout << bef.first << " " << bef.second << "eho" << endl;
        int pos = bin_s(i,bef);
        //if(pos == bef.first || pos == bef.second) pos++;
        //if(pos == bef.first || pos == bef.second) pos++;

        g[ch[i]].push_back(ch[pos]);
        g[ch[pos]].push_back(ch[i]);

        bef.second = bef.first;
        bef.first = pos;
    }
}

bool moq[MAXN];

void Solve(int N)
{
    n = N;
    vector<int>p,o;
    p.push_back(1);
    moq[1] = 1;
    for(int k = 1; k <= 2*n; k++)
    {
        bool f = false;
        for(int i = 2; i <= 2*n; i++)
        {
            if(moq[i]) continue;

            p.push_back(i);
            if(Query(p) != p.size())
            {
                o.push_back(i);
                moq[i] = true;

                f = true;
            }
            p.pop_back();

            if(moq[i]) continue;

            o.push_back(i);
            if(Query(o) != o.size())
            {
                p.push_back(i);
                moq[i] = true;
                f = true;
            }
            o.pop_back();
        }
        if(!f)
        {
            for(int i = 2; i <= 2*n; i++)
            {
                if(!moq[i])
                {
                    moq[i] = 1;
                    p.push_back(i);
                    break;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++) ch[i] = p[i-1];
    for(int i = n+1; i <= 2*n; i++) ch[i] = o[i-n-1];

    for(int i = 1; i <= n; i++) SOLVE4(i);
    /*for(int i = 1; i <= 2*n; i++)
    {
        cout << i << " -> ";
        for(int nb : g[i]) cout << nb << " ";
        cout << endl;
    }*/

    for(int i = 1; i <= 2*n; i++)
    {
        if(g[i].size() == 1)
        {
            if(!vis[i] && !vis[g[i][0]]) Answer(i,g[i][0]);
            vis[i] = 1;
            vis[g[i][0]] = 1;
            continue;
        }

        int ab = Query({i,g[i][0],g[i][1]});
        int ac = Query({i,g[i][0],g[i][2]});
        int bc = Query({i,g[i][1],g[i][2]});

        if(ab == ac) in[g[i][0]] = i;
        if(ab == bc) in[g[i][1]] = i;
        if(bc == ac) in[g[i][2]] = i;
    }
    for(int i = 1; i <= 2*n; i++) ou[in[i]] = i;

    for(int i = 1; i <= 2*n; i++)
    {
        if(vis[i]) continue;

        for(int j = 0; j < 3; j++)
        {
            if(j > g[i].size()-1) break;

            if(g[i][j] != in[i] && g[i][j] != ou[i])
            {
                if(!vis[i] && !vis[g[i][j]]) Answer(i,g[i][j]);
                vis[i] = 1;
                vis[g[i][j]] = 1;
                break;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...