Submission #423752

#TimeUsernameProblemLanguageResultExecution timeMemory
423752tqbfjotldChameleon's Love (JOI20_chameleon)C++14
40 / 100
2 ms456 KiB
#include "chameleon.h" #include <bits/stdc++.h> using namespace std; namespace { int p[505]; int inv[505]; vector<int> adjl[505]; void func(int num, vector<int> opts){ if (opts.size()==1){ adjl[num].push_back(opts[0]); adjl[opts[0]].push_back(num); return; } 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]); } } lhalf.push_back(num); int res = Query(lhalf); if (res!=lhalf.size()){ lhalf.pop_back(); func(num,lhalf); } rhalf.push_back(num); res = Query(rhalf); if (res!=rhalf.size()){ rhalf.pop_back(); func(num,rhalf); } } } void Solve(int N) { if (N<=50){ for (int x = 1; x<=2*N; x++){ for (int y = x+1; y<=2*N; y++){ int res = Query({x,y}); if (res==1){ adjl[x].push_back(y); adjl[y].push_back(x); } } } } else{ vector<int> opt; for (int x = N+1; x<=2*N; x++){ opt.push_back(x); } for (int x = 1; x<=N; x++){ func(x,opt); } } for (int x = 1; x<=2*N; x++){ if (adjl[x].size()==3){ int res1 = Query({x,adjl[x][0],adjl[x][1]}); int res2 = Query({x,adjl[x][1],adjl[x][2]}); int res3 = Query({x,adjl[x][0],adjl[x][2]}); if (res1==1){ p[x] = adjl[x][2]; } else 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 'void {anonymous}::func(int, std::vector<int>)':
chameleon.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int x = 0; x<opts.size(); x++){
      |                     ~^~~~~~~~~~~~
chameleon.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         if (x<opts.size()/2){
      |             ~^~~~~~~~~~~~~~
chameleon.cpp:29:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if (res!=lhalf.size()){
      |         ~~~^~~~~~~~~~~~~~
chameleon.cpp:35:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (res!=rhalf.size()){
      |         ~~~^~~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:68:17: warning: unused variable 'res3' [-Wunused-variable]
   68 |             int res3 = Query({x,adjl[x][0],adjl[x][2]});
      |                 ^~~~
#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...