Language: C++

#include <cstdio>
#include <queue>
#include <climits>
#include <vector>
#include <algorithm>

using namespace std;


char dat[510][510];


int solve(vector<string> dat) {
  int n = dat.size();
  int ans = INT_MAX;

  vector<int> colwhite(n), rowwhite(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dat[i][j] == '.') {
        rowwhite[i]++;
        colwhite[j]++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    int repaint = 0;
    int holecnt = 0;
    for (int k = 0; k < n; k++) {
      if (dat[i][k] == '#') {
        if (colwhite[k] > 0) {
          repaint++;
        }
      }
      else {
        holecnt++;
      }
    }
    if (holecnt == 0) {
      int cur = repaint;
      ans = min(ans, cur);
      continue;
    }
    for (int j = 0; j < n; j++) {
      if (dat[j][i] != '#')
        continue;
      int cur = holecnt;
      cur += repaint;
      if (rowwhite[j] > 0) {
        cur += holecnt;
      }
      ans = min(ans, cur);
    }
    if (holecnt < n && dat[i][i] == '.') { // at least one #
      int cur = 1 + holecnt;
      cur += repaint;
      cur += holecnt;
      ans = min(ans, cur);
    }
  }

  if (ans == INT_MAX)
    ans = -1;
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<string> inp;
  for (int i = 0; i < n; i++) {
    scanf("%s", dat[i]);
    inp.emplace_back(dat[i]);
  }
  printf("%d\n", solve(inp));
  return 0;
}

Compiler output:
a.cc:13:18: error: 'string' was not declared in this scope
   13 | int solve(vector<string> dat) {
      |                  ^~~~~~
a.cc:6:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    5 | #include <algorithm>
  +++ |+#include <string>
    6 | 
a.cc:13:24: error: template argument 1 is invalid
   13 | int solve(vector<string> dat) {
      |                        ^
a.cc:13:24: error: template argument 2 is invalid
a.cc: In function 'int solve(int)':
a.cc:14:15: error: request for member 'size' in 'dat', which is of non-class type 'int'
   14 |   int n = dat.size();
      |               ^~~~
a.cc:20:14: error: invalid types 'int[int]' for array subscript
   20 |       if (dat[i][j] == '.') {
      |              ^
a.cc:31:14: error: invalid types 'int[int]' for array subscript
   31 |       if (dat[i][k] == '#') {
      |              ^
a.cc:46:14: error: invalid types 'int[int]' for array subscript
   46 |       if (dat[j][i] != '#')
      |              ^
a.cc:55:27: error: invalid types 'int[int]' for array subscript
   55 |     if (holecnt < n && dat[i][i] == '.') { // at least one #
      |                           ^
a.cc: In function 'int main()':
a.cc:71:10: error: 'string' was not declared in this scope
   71 |   vector<string> inp;
      |          ^~~~~~
a.cc:71:10: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
a.cc:71:16: error: template argument 1 is invalid
   71 |   vector<string> inp;
      |                ^
a.cc:71:16: error: template argument 2 is invalid
a.cc:74:9: error: request for member 'emplace_back' in 'inp', which is of non-class type 'int'
   74 |     inp.emplace_back(dat[i]);
      |         ^~~~~~~~~~~~