Submission #278043

# Submission time Handle Problem Language Result Execution time Memory
278043 2020-08-21T09:19:12 Z MKopchev Chameleon's Love (JOI20_chameleon) C++14
100 / 100
98 ms 640 KB
#include "chameleon.h"
#include<bits/stdc++.h>

using namespace std;

const int nmax=1e3+42;

vector< pair<int,int> > edges;

vector<int> adj[nmax];

int n_;

int colour[nmax];

void dfs(int node,int col)
{
    if(colour[node]!=-1)return;
    colour[node]=col;

    for(auto k:adj[node])
        dfs(k,!col);
}

void add_edge(int u,int v)
{
    //cout<<"edge "<<u<<" "<<v<<endl;

    adj[u].push_back(v);
    adj[v].push_back(u);
}
void go(int original,vector<int> other)
{
    if(other.size()==0)return;

    while(1)
    {
        vector<int> help=other;
        help.push_back(original);

        if(Query(help)==help.size())return;

        //there is an edge
        vector<int> active=other;

        while(active.size()>1)
        {
            vector<int> groups[2]={{},{}};

            for(int i=0;i<active.size();i++)
                groups[i%2].push_back(active[i]);

            groups[0].push_back(original);

            if(Query(groups[0])==groups[0].size())active=groups[1];
            else
            {
                groups[0].pop_back();
                active=groups[0];
            }

        }

        add_edge(original,active[0]);

        vector<int> other_new={};
        for(auto k:other)
            if(k!=active[0])other_new.push_back(k);

        other=other_new;
    }
}
void make()
{
    for(int i=1;i<=2*n_;i++)
    {
        memset(colour,-1,sizeof(colour));

        for(int j=1;j<i;j++)
            if(colour[j]==-1)dfs(j,0);

        vector<int> groups[2]={{},{}};

        for(int j=1;j<i;j++)
            groups[colour[j]].push_back(j);

        go(i,groups[0]);
        go(i,groups[1]);

        //cout<<"--- "<<query_count<<endl;
    }
}

int love[nmax];

bool solved[nmax];

set<int> blocked[nmax];

void Solve(int N)
{
    n_=N;

    make();

    for(int i=1;i<=2*n_;i++)
        if(adj[i].size()==3)
        {
            if(Query({i,adj[i][0],adj[i][1]})==1)love[i]=adj[i][2];
            else if(Query({i,adj[i][0],adj[i][2]})==1)love[i]=adj[i][1];
            else love[i]=adj[i][0];

            blocked[i].insert(love[i]);
            blocked[love[i]].insert(i);
        }
    for(int i=1;i<=2*n_;i++)
        if(solved[i]==0)
        {
            if(adj[i].size()==1)
            {
                Answer(i,adj[i][0]);
                solved[i]=1;
                solved[adj[i][0]]=1;
            }
        }

    for(int i=1;i<=2*n_;i++)
        if(solved[i]==0)
        {
            for(auto k:adj[i])
                if(blocked[i].count(k)==0)
                {
                    solved[i]=1;
                    solved[k]=1;

                    Answer(i,k);
                }
        }
}

Compilation message

chameleon.cpp: In function 'void go(int, std::vector<int>)':
chameleon.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if(Query(help)==help.size())return;
      |            ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             for(int i=0;i<active.size();i++)
      |                         ~^~~~~~~~~~~~~~
chameleon.cpp:55:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             if(Query(groups[0])==groups[0].size())active=groups[1];
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 46 ms 504 KB Output is correct
4 Correct 38 ms 504 KB Output is correct
5 Correct 38 ms 504 KB Output is correct
6 Correct 35 ms 512 KB Output is correct
7 Correct 35 ms 512 KB Output is correct
8 Correct 35 ms 508 KB Output is correct
9 Correct 37 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 82 ms 504 KB Output is correct
4 Correct 76 ms 632 KB Output is correct
5 Correct 85 ms 504 KB Output is correct
6 Correct 85 ms 504 KB Output is correct
7 Correct 74 ms 504 KB Output is correct
8 Correct 75 ms 504 KB Output is correct
9 Correct 79 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 46 ms 504 KB Output is correct
4 Correct 38 ms 504 KB Output is correct
5 Correct 38 ms 504 KB Output is correct
6 Correct 35 ms 512 KB Output is correct
7 Correct 35 ms 512 KB Output is correct
8 Correct 35 ms 508 KB Output is correct
9 Correct 37 ms 504 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 82 ms 504 KB Output is correct
31 Correct 76 ms 632 KB Output is correct
32 Correct 85 ms 504 KB Output is correct
33 Correct 85 ms 504 KB Output is correct
34 Correct 74 ms 504 KB Output is correct
35 Correct 75 ms 504 KB Output is correct
36 Correct 79 ms 504 KB Output is correct
37 Correct 74 ms 524 KB Output is correct
38 Correct 36 ms 504 KB Output is correct
39 Correct 74 ms 512 KB Output is correct
40 Correct 74 ms 512 KB Output is correct
41 Correct 75 ms 640 KB Output is correct
42 Correct 36 ms 504 KB Output is correct
43 Correct 75 ms 504 KB Output is correct
44 Correct 80 ms 512 KB Output is correct
45 Correct 98 ms 504 KB Output is correct