Submission #423903

# Submission time Handle Problem Language Result Execution time Memory
423903 2021-06-11T14:02:55 Z tqbfjotld Chameleon's Love (JOI20_chameleon) C++14
60 / 100
57 ms 576 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;
    }
   // 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);
        }
    }
}

}

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 (groupnum[y]) group1.push_back(y);
            else group0.push_back(y);
        }
        int t = 0;
        if (func(x,group1,1,true)){
            t++;
            vector<int> temp;
            for (auto y : group1){
                if (y>adjl[x][0]) temp.push_back(y);
            }
            if (temp.size()>0 && func(x,temp,1,true)){
                t++;
                swap(temp,group1);
                temp.clear();
                for (auto y : group1){
                    if (y>adjl[x][1]) temp.push_back(y);
                }
                if (temp.size()>0 && func(x,temp,1,true)){
                    t++;
                }
            }
        }
        if (t<3 && group0.size()>0 && func(x,group0,1,true)){
            t++;
            vector<int> temp;
            for (auto y : group0){
                if (y>adjl[x][t-1]) temp.push_back(y);
            }
            if (t<3 && temp.size()>0 && func(x,temp,1,true)){
                t++;
                swap(temp,group0);
                temp.clear();
                for (auto y : group0){
                    if (y>adjl[x][t-1]) temp.push_back(y);
                }
                if (t<3 && 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:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int x = 0; x<opts.size(); x++){
      |                     ~^~~~~~~~~~~~
chameleon.cpp:27:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if (x<opts.size()/2){
      |             ~^~~~~~~~~~~~~~
chameleon.cpp:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     if (res!=lhalf.size()){
      |         ~~~^~~~~~~~~~~~~~
chameleon.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     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 Incorrect 46 ms 328 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 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 384 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 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 2 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 2 ms 328 KB Output is correct
17 Correct 2 ms 328 KB Output is correct
18 Correct 2 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 51 ms 404 KB Output is correct
4 Correct 55 ms 388 KB Output is correct
5 Correct 52 ms 456 KB Output is correct
6 Correct 57 ms 464 KB Output is correct
7 Correct 51 ms 396 KB Output is correct
8 Correct 51 ms 576 KB Output is correct
9 Correct 53 ms 384 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 Incorrect 46 ms 328 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -