Language: C++

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

// ?????¨??????????????°????§£????????????????????????
class BipartiteMatching{
private:
  int V;
  vector<vector<int> > G; // ??£??\?????????
  vector<int> match; // ??????????????°?????????
  vector<bool> used; // DFS??§?????¨?????????????????????????????°
  
  // ?¢?????????????DFS??§??¢???
  bool dfs(int v){
    // ??????????????¨???????????????
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
      int u = G[v][i];
      int w = match[u];
      // w???????????¨ or ??????????????¨???????????´???&&?????????????°´??????????????´???
      if(w < 0 || (!used[w] && dfs(w))){
        // v??¨u??????????????????
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
public:
  // ?????????????????????
  BipartiteMatching(int size){
    V = size;
    G = vector<vector<int> >(size);
    match = vector<int>(size);
    used = vector<bool>(size);
  }

  // ??????????????????
  void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  // ?????¨??°??????????????§??????????????°????±???????
  int flow(){
    int res = 0;
    for(int i = 0; i < match.size(); i++){ match[i] = -1; }
    // ?????????????????????
    for(int v = 0; v < V; v++){
      if(match[v] < 0){
        for(int i = 0; i < used.size(); i++){ used[i] = false; }
        if(dfs(v)){ res++; }
      }
    }
    return res;
  }

  // ??????????????°??§???????????£?????????????????????
  vector<int> left_out(void){
    vector<int> leftout;
    for(int i = 0; i < match.size(); i++){
      if(match[i] == -1){ leftout.push_back(i); }
    }
    return leftout;
  }
};


// ?????¶???????????§???(????§°)????§£????????????????????????
// ??????: ?????????cost??\?????§??????????????????????????????
class ConditionalMaxFlow{
private:
  static const int inf = 1e9;
  struct edge{ int to, cap, cost, rev; };
  int V;
  vector<vector<edge> > G;
  vector<int> dist, prevv, preve;
  int my_min(int a, int b){ return a < b ? a : b; }
public:
  // ?????????????????????
  ConditionalMaxFlow(int size){
    V = size;
    G = vector<vector<edge> >(size);
    dist = vector<int>(size);
    prevv = vector<int>(size);
    preve = vector<int>(size);
  }

  // ????????????
  void add_edge(int from, int to, int cap, int cost){
    G[from].push_back((edge){to, cap, cost, G[to].size()});
    G[to].push_back((edge){from, 0, -cost, G[from].size()-1});
  }

  // s??????t?????§?????????cost??\?????§?????????????????§???????±???????
  int flow(int s, int t, int cost){
    int res = 0, f = 0;
    
    while(res < cost){
      // ???????????????????????????????????????s-t????????????????±???????
      for(int i = 0; i < dist.size(); i++)
        dist[i] = inf;
      dist[s] = 0;

      bool update;
      do{
        update = false;
        for(int v = 0; v < V; v++){
          if(dist[v] == inf){ continue; }
          for(int i = 0; i < G[v].size(); i++){
            edge &e = G[v][i];
            if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
              dist[e.to] = dist[v] + e.cost;
              prevv[e.to] = v;
              preve[e.to] = i;
              update = true;
            }
          }
        }
      }while(update);

      // ??????????????????
      if(dist[t] == inf){ break; }

      // s-t????????????????????£??????????????????
      int d = 1e9;
      for(int v = t; v != s; v = prevv[v]){
        d = my_min(d, G[prevv[v]][preve[v]].cap);
      }

      // ???????????????????????????????????¢??????
      if(res + (d * dist[t]) > cost){ break; }
      
      res += d * dist[t];
      f += d;
      
      for(int v = t; v != s; v = prevv[v]){
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    
    return f;
  }
};


int main(void){
  int A, B, K;
  string a, b;

  cin >> A >> B >> K;

  // ?????§???????????????????????????
  vector<vector<int> > compatible(A, vector<int>(B));
  for(int i = 0; i < A; i++){
    cin >> a;
    for(int j = 0; j < a.size(); j++){ compatible[i][j] = (a[j] != '1') ? 0 : 1; }
  }
  for(int i = 0; i < B; i++){
    cin >> b;
    for(int j = 0; j < b.size(); j++){ compatible[j][i] += (b[j] != '1') ? 0 : 1; }
  }
  
  // ?????§???????????¨??????????????????????????¨?????????????????????????????????????£???§????????????????????¢?????????
  BipartiteMatching bm = BipartiteMatching(A + B);
  for(int i = 0; i < A; i++){
    for(int j = 0; j < B; j++){
      if(compatible[i][j] == 0){ bm.add_edge(i, A + j); }
    }
  }
  int result = bm.flow();
  
  // ?¬?????????????????????£????\´????????¬??£??????????????¨????????????
  vector<int> leftout = bm.left_out();
  sort(leftout.begin(), leftout.end());

  ConditionalMaxFlow cmf = ConditionalMaxFlow(leftout.size() + 2);
  int loA; // ??????????????????A?????°
  
  // ???????????????????£???§???????????????
  // ??????????????????????????????????????????????????????K??\?????§????????????????????¢?????????
  for(loA = 0; leftout[loA] < A; loA++){
    cmf.add_edge(leftout.size(), loA, 1, 0);
  }
  for(int i = loA; i < leftout.size(); i++){
    cmf.add_edge(i, leftout.size() + 1, 1, 0);
    for(int j = 0; j < loA; j++){
      cmf.add_edge(j, i, 1, compatible[leftout[j]][leftout[i]-A]);
    }
  }
  result += cmf.flow(leftout.size(), leftout.size() + 1, K);


  // ???????????????
  cout << result << endl;

  return 0;
}

Compiler output:
a.cc: In member function 'void ConditionalMaxFlow::add_edge(int, int, int, int)':
a.cc:93:55: warning: narrowing conversion of '(&((ConditionalMaxFlow*)this)->ConditionalMaxFlow::G.std::vector<std::vector<ConditionalMaxFlow::edge> >::operator[](((std::vector<std::vector<ConditionalMaxFlow::edge> >::size_type)to)))->std::vector<ConditionalMaxFlow::edge>::size()' from 'std::vector<ConditionalMaxFlow::edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   93 |     G[from].push_back((edge){to, cap, cost, G[to].size()});
      |                                             ~~~~~~~~~~^~
a.cc:94:58: warning: narrowing conversion of '((&((ConditionalMaxFlow*)this)->ConditionalMaxFlow::G.std::vector<std::vector<ConditionalMaxFlow::edge> >::operator[](((std::vector<std::vector<ConditionalMaxFlow::edge> >::size_type)from)))->std::vector<ConditionalMaxFlow::edge>::size() - 1)' from 'std::vector<ConditionalMaxFlow::edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   94 |     G[to].push_back((edge){from, 0, -cost, G[from].size()-1});
      |                                            ~~~~~~~~~~~~~~^~
a.cc: In function 'int main()':
a.cc:179:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
  179 |   sort(leftout.begin(), leftout.end());
      |   ^~~~
      |   sqrt