Submission #424015

# Submission time Handle Problem Language Result Execution time Memory
424015 2021-06-11T15:22:59 Z tqbfjotld Chameleon's Love (JOI20_chameleon) C++14
100 / 100
67 ms 456 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

namespace {

int p[1005];
int inv[1005];
vector<int> adjl[1005];

int func(int num, vector<int> opts, int lim, bool need_verify = false){
   // printf("%d??\n",opts.size());
    if (opts.size()==1){
        if (need_verify){
            int res = Query({num,opts[0]});
            if (res==2){
                return 0;
            }
        }
        adjl[num].push_back(opts[0]);
        adjl[opts[0]].push_back(num);
        return 1;
    }
    if (need_verify){
        opts.push_back(num);
        int res = Query(opts);
        if (res==opts.size()){
            opts.pop_back();
            return 0;
        }
        opts.pop_back();
    }
   // random_shuffle(opts.begin(),opts.end()); ///not needed?
    vector<int> lhalf, rhalf;
    for (int x = 0; x<opts.size(); x++){
        if (x<opts.size()/2){
            lhalf.push_back(opts[x]);
        }
        else{
            rhalf.push_back(opts[x]);
        }
    }
    int t = 0;
    lhalf.push_back(num);
    int res = Query(lhalf);
    if (res!=lhalf.size()){
        lhalf.pop_back();
        t += func(num,lhalf,lim);
    }
    if (t>=lim) return t;
    rhalf.push_back(num);
    if (rhalf.size()!=2){
        rhalf.pop_back();
        t+= func(num,rhalf,lim-t);
    }
    else if ( Query(rhalf)!=rhalf.size()){
      //  printf("queried twice\n");
        rhalf.pop_back();
        t+= func(num,rhalf,lim-t);
    }
    return t;
}

int groupnum[1005];

void relabel(int node, bool flag){
    groupnum[node] = flag;
    for (auto x : adjl[node]){
        if (groupnum[x]==-1){
            relabel(x,!flag);
        }
    }
}
const int maxedges = 3;

}

void Solve(int N) {
    func(1,vector<int>({2}),1,true);
    for (int x = 3; x<=2*N; x++){
        for (int y = 1; y<x; y++){
            groupnum[y] = -1;
        }
        for (int y = 1; y<x; y++){
            if (groupnum[y]==-1) relabel(y,true);
        }
        vector<int> group0,group1;
        for (int y = 1; y<x; y++){
            if (adjl[y].size()==maxedges) continue;
            if (groupnum[y]) group1.push_back(y);
            else group0.push_back(y);
        }
        if (group1.size()<group0.size()) swap(group0,group1);
        int t = 0;
        if (func(x,group1,1,true)){
            t++;
            vector<int> temp;
            for (auto y : group1){
                if (adjl[y].size()==maxedges) continue;
                if (y>adjl[x][0]) temp.push_back(y);
            }
            if (t<maxedges && temp.size()>0 && func(x,temp,1,true)){
                t++;
                swap(temp,group1);
                temp.clear();
                for (auto y : group1){
                    if (adjl[y].size()==maxedges) continue;
                    if (y>adjl[x][1]) temp.push_back(y);
                }
                if (t<maxedges && temp.size()>0 && func(x,temp,1,true)){
                    t++;
                }
            }
        }
        if (t<maxedges && group0.size()>0 && func(x,group0,1,true)){
            t++;
            vector<int> temp;
            for (auto y : group0){
                if (adjl[y].size()==maxedges) continue;
                if (y>adjl[x][t-1]) temp.push_back(y);
            }
            if (t<maxedges && temp.size()>0 && func(x,temp,1,true)){
                t++;
                swap(temp,group0);
                temp.clear();
                for (auto y : group0){
                    if (adjl[y].size()==maxedges) continue;
                    if (y>adjl[x][t-1]) temp.push_back(y);
                }
                if (t<maxedges && temp.size()>0 && func(x,temp,1,true)){
                    t++;
                }
            }
        }
    }
  //  printf("cur query count = %d\n",query_count);
    for (int x = 1; x<=2*N; x++){
        if (adjl[x].size()==3){
            int res1 = Query({x,adjl[x][0],adjl[x][1]});
            if (res1==1){
                p[x] = adjl[x][2];
            }
            else{

                int res2 = Query({x,adjl[x][1],adjl[x][2]});
                if (res2==1){
                    p[x] = adjl[x][0];
                }
                else{
                    p[x] = adjl[x][1];
                }
            }
            inv[p[x]] = x;
        }
    }
    for (int x = 1; x<=2*N; x++){
        if (adjl[x].size()<3){
            if (x<adjl[x][0]){
                Answer(x,adjl[x][0]);
            }
        }
        else{
            int other = -1;
            for (auto y : adjl[x]){
                if (y==p[x]) continue;
                if (y==inv[x]) continue;
                other = y;
            }
            if (x<other){
                Answer(x,other);
            }
        }
    }
}

Compilation message

chameleon.cpp: In function 'int {anonymous}::func(int, std::vector<int>, int, bool)':
chameleon.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if (res==opts.size()){
      |             ~~~^~~~~~~~~~~~~
chameleon.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int x = 0; x<opts.size(); x++){
      |                     ~^~~~~~~~~~~~
chameleon.cpp:36:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if (x<opts.size()/2){
      |             ~^~~~~~~~~~~~~~
chameleon.cpp:46:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     if (res!=lhalf.size()){
      |         ~~~^~~~~~~~~~~~~~
chameleon.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     else if ( Query(rhalf)!=rhalf.size()){
      |               ~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 25 ms 408 KB Output is correct
4 Correct 35 ms 456 KB Output is correct
5 Correct 25 ms 328 KB Output is correct
6 Correct 25 ms 324 KB Output is correct
7 Correct 25 ms 412 KB Output is correct
8 Correct 25 ms 400 KB Output is correct
9 Correct 27 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 3 ms 328 KB Output is correct
17 Correct 2 ms 328 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 45 ms 392 KB Output is correct
4 Correct 43 ms 400 KB Output is correct
5 Correct 46 ms 328 KB Output is correct
6 Correct 47 ms 380 KB Output is correct
7 Correct 44 ms 408 KB Output is correct
8 Correct 43 ms 328 KB Output is correct
9 Correct 44 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 25 ms 408 KB Output is correct
4 Correct 35 ms 456 KB Output is correct
5 Correct 25 ms 328 KB Output is correct
6 Correct 25 ms 324 KB Output is correct
7 Correct 25 ms 412 KB Output is correct
8 Correct 25 ms 400 KB Output is correct
9 Correct 27 ms 384 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 0 ms 328 KB Output is correct
17 Correct 0 ms 328 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 3 ms 328 KB Output is correct
26 Correct 2 ms 328 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 0 ms 328 KB Output is correct
29 Correct 0 ms 328 KB Output is correct
30 Correct 45 ms 392 KB Output is correct
31 Correct 43 ms 400 KB Output is correct
32 Correct 46 ms 328 KB Output is correct
33 Correct 47 ms 380 KB Output is correct
34 Correct 44 ms 408 KB Output is correct
35 Correct 43 ms 328 KB Output is correct
36 Correct 44 ms 404 KB Output is correct
37 Correct 67 ms 392 KB Output is correct
38 Correct 30 ms 328 KB Output is correct
39 Correct 41 ms 396 KB Output is correct
40 Correct 44 ms 328 KB Output is correct
41 Correct 42 ms 328 KB Output is correct
42 Correct 25 ms 328 KB Output is correct
43 Correct 43 ms 400 KB Output is correct
44 Correct 41 ms 392 KB Output is correct
45 Correct 40 ms 392 KB Output is correct