Submission #805407

#TimeUsernameProblemLanguageResultExecution timeMemory
805407ZHIRDILBILDIZLibrary (JOI18_library)C++14
0 / 100
42 ms436 KiB
#include<bits/stdc++.h> #include"library.h" using namespace std ; const int N = 1e3 ; //int Query(vector<int>& v) //{ // int num ; // cout << "? " ; // for(int i : v) // cout << i << ' ' ; // cout << '\n' ; // cin >> num ; // return num ; //} //void Answer(vector<int>& res) //{ // cout << "! " ; // for(int i : res) // cout << i << ' ' ; // exit(0) ; //} vector<int> qr, ans, v[N + 1] ; void dfs(int city, int last) { ans.push_back(city) ; for(int i : v[city]) { if(i == last) continue ; dfs(i, city) ; } } int get_kol(vector<int> qr) { int l = 0, r = 0, kol = 0 ; for(int i = 0 ; i < qr.size() ; i++) if(qr[i]) { if(!l)l = i + 1 ; r = i + 1 ; } for(int i = 0 ; i < qr.size() ; i++) { if(!qr[i]) continue ; for(int j : v[i + 1]) if(l <= j && j <= r) kol++ ; } return kol / 2 ; } void Solve(int n) { for(int i = 1 ; i <= n ; i++) qr.push_back(0) ; for(int i = 1 ; i < n ; i++) { int l1 = 0, r1 = n + 1, l2 = 0, r2 ; bool flag = 0 ; while(l1 + 1 < r1) { int mid = (l1 + r1) >> 1, num ; for(int j = 1 ; j <= mid ; j++) qr[j - 1] = 1 ; num = get_kol(qr) ; // cout<<"1+ "<<l1<<' '<<r1 << ' ' << num <<'\n' ; if(Query(qr) != mid - get_kol(qr)) r1 = mid ; else l1 = mid ; for(int j = 1 ; j <= mid ; j++) qr[j - 1] = 0 ; } r2 = r1 ; while(l2 + 1 < r2) { int mid = (l2 + r2) >> 1, num ; for(int j = mid ; j <= r1 ; j++) qr[j - 1] = 1 ; num = get_kol(qr) ; // cout<<"2+ "<<l2<<' '<<r2 << ' ' << num <<'\n' ; if(Query(qr) != (r1 - mid + 1) - get_kol(qr)) l2 = mid ; else r2 = mid ; for(int j = mid ; j <= r1 ; j++) qr[j - 1] = 0 ; } // cout << l2 << '-' << r1 << '\n' ; v[l2].push_back(r1) ; v[r1].push_back(l2) ; } for(int i = 1 ; i <= n ; i++) if(v[i].size() == 1) { dfs(i, 0) ; break ; } Answer(ans) ; } //signed main() //{ // int n ; // cin >> n ; // Solve(n) ; // return 0 ; //}

Compilation message (stderr)

library.cpp: In function 'int get_kol(std::vector<int>)':
library.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 0 ; i < qr.size() ; i++)
      |                     ~~^~~~~~~~~~~
library.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0 ; i < qr.size() ; i++)
      |                     ~~^~~~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:62:39: warning: variable 'num' set but not used [-Wunused-but-set-variable]
   62 |             int mid = (l1 + r1) >> 1, num ;
      |                                       ^~~
library.cpp:77:39: warning: variable 'num' set but not used [-Wunused-but-set-variable]
   77 |             int mid = (l2 + r2) >> 1, num ;
      |                                       ^~~
library.cpp:59:14: warning: unused variable 'flag' [-Wunused-variable]
   59 |         bool flag = 0 ;
      |              ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...