Language: C++


#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 10;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
//const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
 
string a[N];
 
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, 0, n) {
        cin >> a[i];
    }
    int ans = inf;
    rep(mask, 0, (1 << (n - 1))) {
        int cnt = __builtin_popcount(mask);
        int tot = cnt;
        vector<int> cur(cnt + 1, 0);
        rep(j, 0, m) {
            int p = 0;
            rep(i, 0, n) {
                cur[p] += (a[i][j] == '1');
                if ((mask >> i) & 1) {
                    p++;
                }
            }
            bool bad = false;
            rep(i, 0, sz(cur)) {
                if (cur[i] > k) {
                    bad = true;
                }
            }
            if (bad) {
                tot++;
                fill(cur.begin(), cur.end(), 0);
                int p = 0;
                rep(i, 0, n) {
                    cur[p] += (a[i][j] == '1');
                    if ((mask >> i) & 1) {
                        p++;
                    }
                }
                bool bad = false;
                rep(i, 0, sz(cur)) {
                    if (cur[i] > k) {
                        bad = true;
                    }
                }
                if (bad) {
                    tot = inf;
                }
            }
        }
        setmin(ans, tot);
    }
    cout << ans << "\n";
    return 0;
}

Compiler output:
a.cc:35:19: error: 'atan2' was not declared in this scope
   35 | const double pi = atan2(0, -1);
      |                   ^~~~~
a.cc:38:1: error: 'string' does not name a type
   38 | string a[N];
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:44:5: error: 'ios_base' has not been declared
   44 |     ios_base::sync_with_stdio(0);
      |     ^~~~~~~~
a.cc:45:5: error: 'cin' was not declared in this scope
   45 |     cin.tie(0);
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:46:5: error: 'cout' was not declared in this scope
   46 |     cout.precision(20);
      |     ^~~~
a.cc:46:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:47:13: error: 'fixed' was not declared in this scope
   47 |     cout << fixed;
      |             ^~~~~
a.cc:1:1: note: 'std::fixed' is defined in header '<ios>'; this is probably fixable by adding '#include <ios>'
  +++ |+#include <ios>
    1 | 
a.cc:53:16: error: 'a' was not declared in this scope
   53 |         cin >> a[i];
      |                ^
a.cc:59:9: error: 'vector' was not declared in this scope
   59 |         vector<int> cur(cnt + 1, 0);
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | 
a.cc:59:16: error: expected primary-expression before 'int'
   59 |         vector<int> cur(cnt + 1, 0);
      |                ^~~
a.cc:63:17: error: 'cur' was not declared in this scope
   63 |                 cur[p] += (a[i][j] == '1');
      |                 ^~~
a.cc:63:28: error: 'a' was not declared in this scope
   63 |                 cur[p] += (a[i][j] == '1');
      |                            ^
a.cc:69:26: error: 'cur' was not declared in this scope
   69 |             rep(i, 0, sz(cur)) {
      |                          ^~~
a.cc:6:45: note: in definition of macro 'rep'
    6 | #define rep(i, l, r) for (int i = (l); i < (r); i++)
      |                                             ^
a.cc:69:23: note: in expansion of macro 'sz'
   69 |             rep(i, 0, sz(cur)) {
      |                       ^~
a.cc:76:22: error: 'cur' was not declared in this scope
   76 |                 fill(cur.begin(), cur.end(), 0);
      |                      ^~~
a.cc:76:17: error: 'fill' was not declared in this scope
   76 |                 fill(cur.begin(), cur.end(), 0);
      |                 ^~~~
a.cc:79:32: error: 'a' was not declared in this scope
   79 |                     cur[p] += (a[i][j] == '1');
      |                                ^