Submission #140071

#TimeUsernameProblemLanguageResultExecution timeMemory
140071mahmoudbadawyLibrary (JOI18_library)C++17
100 / 100
545 ms552 KiB
#include <bits/stdc++.h> #include "library.h" using namespace std; // Query() // Answer() int n; int query(vector<int> v) { vector<int> m(n,0); for(int i:v) m[i]=1; return Query(m); } int get(int x,vector<int> v) { if(v.size()==1) { /*v.push_back(x); if(query(v)==2) return -1;*/ return v[0]; } vector<int> mm; for(int i=0;i<v.size()/2;i++) mm.push_back(v[i]); int cur=query(mm); mm.push_back(x); if(query(mm)<=cur) { mm.pop_back(); return get(x,mm); } mm.clear(); for(int i=v.size()/2;i<v.size();i++) mm.push_back(v[i]); return get(x,mm); } vector<int> adj[1005]; vector<int> ans; int vis[1005]; void build(int x,int pa) { vis[x]=1; ans.push_back(x+1); for(int i:adj[x]) if(!vis[i]) build(i,x); } vector<int> hv1; int got(int x) { if(adj[x].size()==2) return 1; if(hv1[0]==x||hv1[1]==x) if(adj[x].size()==1) return 1; return 0; } void Solve(int N) { if(N==1) {Answer({1});return;} n=N; for(int i=0;i<N;i++) { vector<int> m(N,1); m[i]=0; if(Query(m)==1) hv1.push_back(i); } // calls = edges/2 -> 2000/2 -> 1000 int calls=0; for(int i=0;i<N;i++) { while(true){ if(got(i)) break; vector<int> ss; for(int j=0;j<N;j++) { bool ok=1; for(int k:adj[i]) ok&=(k!=j); ok&=(i!=j); ok&=(!got(j)); if(ok) ss.push_back(j); } int x=get(i,ss); if(x!=-1) {calls++; adj[i].push_back(x); adj[x].push_back(i);} else assert(i!=i); } //cout << i+1 << " Found " << x+1 << endl; } //cout << calls << endl; /*for(int i=0;i<n;i++) { cout << i+1 << ": "; for(int j:adj[i]) cout << j+1 << " "; cout << endl; }*/ for(int i=0;i<n;i++) { if(adj[i].size()==1) { build(i,-1); break; } } Answer(ans); }

Compilation message (stderr)

library.cpp: In function 'int get(int, std::vector<int>)':
library.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size()/2;i++)
              ~^~~~~~~~~~~
library.cpp:36:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=v.size()/2;i<v.size();i++)
                       ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...