Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;
map<set<int>,int>memo;

int M,N;
vector<string>v;
int dfs(set<int> &t){
	if(t.size()==1)return 0;
	if(memo.find(t)!=memo.end())return memo[t];
	int r=1<<30;
	for(int j=0;j<M;j++){
		set<int>a,b;
		for(auto &e:t)(v[e][j]=='0'?a:b).push_back(e);
		if(a.size()&&b.size())r=min(r,max(dfs(a),dfs(b))+1);
	}
	return memo[t]=r;
}

int main(){
	for(;cin>>M>>N,M;){
		v.resize(N);
		for(int i=0;i<N;i++)cin>>v[i];
		set<int>t(N);
		for(int i=0;i<N;i++)t.insert(i);
		memo.clear();
		printf("%d\n",dfs(t));
	}
}

Compiler output:
a.cc: In function 'int dfs(std::set<int>&)':
a.cc:19:50: error: 'class std::set<int>' has no member named 'push_back'
   19 |                 for(auto &e:t)(v[e][j]=='0'?a:b).push_back(e);
      |                                                  ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:29:28: error: no matching function for call to 'std::set<int>::set(int&)'
   29 |                 set<int>t(N);
      |                            ^
In file included from /usr/include/c++/14/set:63,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_set.h:273:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const allocator_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  273 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:273:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:210:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  210 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:210:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:193:9: note: candidate: 'template<class _InputIterator> std::set<_Key, _Compare, _Alloc>::set(_InputIterator, _InputIterator) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  193 |         set(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:193:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:267:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const allocator_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; allocator_type = std::allocator<int>]'
  267 |       set(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:267:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:261:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::__type_identity_t<_Alloc> = std::allocator<int>]'
  261 |       set(set&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:261:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:257:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; std::__type_identity_t<_Alloc> = std::allocator<int>]'
  257 |       set(const set& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:257:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_set.h:253:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const allocator_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; allocator_type = std::allocator<int>]'
  253 |       set(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:253:33: note:   no known conversion for argument 1 from 'int' to 'const std::set<int>::allocator_type&' {aka 'const std::allocator<int>&'}
  253 |       set(const allocator_type& __a)
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:245:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::initializer_list<_Tp>, const _Compare&, const allocator_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; allocator_type = std::allocator<int>]'
  245 |       set(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:245:40: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
  245 |       set(initializer_list<value_type> __l,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:233:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(std::set<_Key, _Compare, _Alloc>&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  233 |       set(set&&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:233:11: note:   no known conversion for argument 1 from 'int' to 'std::set<int>&&'
  233 |       set(set&&) = default;
      |           ^~~~~
/usr/include/c++/14/bits/stl_set.h:225:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const std::set<_Key, _Compare, _Alloc>&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  225 |       set(const set&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:225:11: note:   no known conversion for argument 1 from 'int' to 'const std::set<int>&'
  225 |       set(const set&) = default;
      |           ^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:178:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set(const _Compare&, const allocator_type&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>; allocator_type = std::allocator<int>]'
  178 |       set(const _Compare& __comp,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:178:27: note:   no known conversion for argument 1 from 'int' to 'const std::less<int>&'
  178 |       set(const _Compare& __comp,
      |           ~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_set.h:169:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::set() [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  169 |       set() = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:169:7: note:   candidate expects 0 arguments, 1 provided