Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll h, w, k, a, b, x, y;
  in3(h, w, k);
  vector<vector<ll>> c(h, vector<ll> (w));
  vector<vector<ll>> d(h, vector<ll> (w));
  char f;
  rep(i, h){
    rep(j, w){
      in(f);
      a = stoi(f);
      c[i][j] = a;
      d[i][j] = a;
    }
  }
  a = 0;
  bool p, q;
  while(a < h - 1){
    b = a + 1;
    p = false;
    while(b < h){
      if(c[b][0] < 100)
        break;
      else
        b++;
      if(b == h)
        p = true;
    }
    if(p)
      break;
    q = true;
    rep(i, w){
      if(c[a][i] + c[b][i] > k)
        q = false;
    }
    if(q){
      rep(i, w)
        c[a][i] += c[b][i];
      c[b][0] = 100;
    }
    else
      a = b;
  }
  a = 0;
  while(a < w - 1){
    b = a + 1;
    p = false;
    while(b < w){
      if(c[0][b] < 100)
        break;
      else
        b++;
      if(b == w)
        p = true;
    }
    if(p)
      break;
    q = true;
    rep(i, h){
      if(c[i][a] + c[i][b] > k)
        q = false;
    }
    if(q){
      rep(i, h)
        c[i][a] += c[i][b];
      c[0][b] = 100;
    }
    else
      a = b;
  }
  a = 0;
  while(a < w - 1){
    b = a + 1;
    p = false;
    while(b < w){
      if(d[0][b] < 100)
        break;
      else
        b++;
      if(b == w)
        p = true;
    }
    if(p)
      break;
    q = true;
    rep(i, h){
      if(d[i][a] + d[i][b] > k)
        q = false;
    }
    if(q){
      rep(i, h)
        d[i][a] += d[i][b];
      d[0][b] = 100;
    }
    else
      a = b;
  }
  a = 0;
  while(a < h - 1){
    b = a + 1;
    p = false;
    while(b < h){
      if(d[b][0] < 100)
        break;
      else
        b++;
      if(b == h)
        p = true;
    }
    if(p)
      break;
    q = true;
    rep(i, w){
      if(d[a][i] + d[b][i] > k)
        q = false;
    }
    if(q){
      rep(i, w)
        d[a][i] += d[b][i];
      d[b][0] = 100;
    }
    else
      a = b;
  }
  a = h + w - 2;
  b = a;
  rep(i, h){
    if(c[i][0] >= 100)
      a--;
    if(d[i][0] >= 100)
      b--;
  }
  rep(j, w){
    if(c[0][j] >= 100)
      a--;
    if(d[0][j] >= 100)
      b--;
  }
  a = min(a, b);
  out(a);
  memi;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:15: error: no matching function for call to 'stoi(char&)'
   26 |       a = stoi(f);
      |           ~~~~^~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:4164:3: note: candidate: 'int std::__cxx11::stoi(const std::string&, std::size_t*, int)'
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4164:22: note:   no known conversion for argument 1 from 'char' to 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'}
 4164 |   stoi(const string& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:4432:3: note: candidate: 'int std::__cxx11::stoi(const std::wstring&, std::size_t*, int)'
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |   ^~~~
/usr/include/c++/14/bits/basic_string.h:4432:23: note:   no known conversion for argument 1 from 'char' to 'const std::wstring&' {aka 'const std::__cxx11::basic_string<wchar_t>&'}
 4432 |   stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
      |        ~~~~~~~~~~~~~~~^~~~~