Submission #423903

#TimeUsernameProblemLanguageResultExecution timeMemory
423903tqbfjotldChameleon's Love (JOI20_chameleon)C++14
60 / 100
57 ms576 KiB
#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 (stderr)

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 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...