Language: C++

#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll h,w,k ;
	cin >> h >> w >> k ;
	vvll cho(h+2,vll(w+2,0)) ;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			char c ; cin >> c ;
			cho.at(i).at(j) = (c=='1') ;
		}
	}
	vvll sum(h+2,vll(w+2,0)) ;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w+1;j++){
			sum.at(i).at(j) = sum.at(i).at(j-1)+cho.at(i).at(j) ;
		}
	}
	for(int j=1;j<=w+1;j++){
		for(int i=1;i<=h+1;i++){
			sum.at(i).at(j) += sum.at(i-1).at(j) ;
		}
	}
	if(h==1){
		ll pos = 0 ;
		ll ans = 0 ;
		for(int i=1;i<=w-1;i++){
			if(sum.at(1).at(i)-sum.at(1).at(pos)<=k&&sum.at(1).at(i+1)-sum.at(1).at(pos)>k){
				ans++ ;
				pos = i ;
			}
		}
		cout << ans << endl ;
		return 0 ;
	}
	ll ans = 10000000 ;
	for(int i=0;i<(1<<(h-1));i++){
		bitset<15> bit(i) ;
		ll sub = 0 ;
		for(int j=0;j<h;j++) if(bit[j]) sub++ ;
		vll yoko ;
		for(int j=0;j<h;j++) if(bit[j]) yoko.push_back(j+1) ;
		if(sub==0){
			ll pos = 0 ;
			ll subcnt = 0 ;
			for(int j=1;j<=w;j++){
				if(sum.at(h).at(j)-sum.at(h).at(pos)>k){
					pos = j-1 ;
					subcnt++ ;
				}
			}
			if(ans>subcnt) ans = subcnt ;
			for(int j=1;j<=w;j++){
				if(sum.at(h).at(j)-sum.at(h).at(j-1)>k) ans = 1000000 ;
			}
//			cout << subcnt << endl ;
			continue ;
		}
		ll pos = 0 ;
		ll subcnt = 0 ;
		for(int j=1;j<=w;j++){
			bool ok = true ;
			for(int l=0;l<sub+1;l++){
				if(l==0){
//					cout << sum.at(yoko.at(0)).at(j)-sum.at(yoko.at(0)).at(pos) << " " ;
					if(sum.at(yoko.at(0)).at(j)-sum.at(yoko.at(0)).at(pos)>k){ 
						ok = false ; 
						if(j==pos+1) subcnt = 10000 ;
					}
				}else if(l==sub){
					if(sum.at(h).at(j)-sum.at(h).at(pos)-sum.at(yoko.at(sub-1)).at(j)+sum.at(yoko.at(sub-1)).at(pos)>k){ ok = false ;if(j==pos+1) subcnt = 10000 ;}
				}else{
					if(sum.at(yoko.at(l)).at(j)-sum.at(yoko.at(l)).at(pos)-sum.at(yoko.at(l-1)).at(j)+sum.at(yoko.at(l-1)).at(pos)>k) [ok = false ;if(j==pos+1) subcnt = 10000 ;}
				}
			}
			if(!ok){
				pos = j-1 ;
				subcnt++ ;
			}
		}
//		cout << endl ;
		if(ans>sub+subcnt) ans = sub+subcnt ;
//		cout << sub+subcnt << endl ;
	}
	cout << ans << endl ;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:105:166: error: expected ',' before ';' token
  105 |                                         if(sum.at(yoko.at(l)).at(j)-sum.at(yoko.at(l)).at(pos)-sum.at(yoko.at(l-1)).at(j)+sum.at(yoko.at(l-1)).at(pos)>k) [ok = false ;if(j==pos+1) subcnt = 10000 ;}
      |                                                                                                                                                                      ^~
      |                                                                                                                                                                      ,
a.cc:105:167: error: expected identifier before ';' token
  105 |                                         if(sum.at(yoko.at(l)).at(j)-sum.at(yoko.at(l)).at(pos)-sum.at(yoko.at(l-1)).at(j)+sum.at(yoko.at(l-1)).at(pos)>k) [ok = false ;if(j==pos+1) subcnt = 10000 ;}
      |                                                                                                                                                                       ^
a.cc:105:166: error: expected ']' before ';' token
  105 |                                         if(sum.at(yoko.at(l)).at(j)-sum.at(yoko.at(l)).at(pos)-sum.at(yoko.at(l-1)).at(j)+sum.at(yoko.at(l-1)).at(pos)>k) [ok = false ;if(j==pos+1) subcnt = 10000 ;}
      |                                                                                                                                                                      ^~
      |                                                                                                                                                                      ]
a.cc: In lambda function:
a.cc:105:167: error: expected '{' before ';' token
  105 |                                         if(sum.at(yoko.at(l)).at(j)-sum.at(yoko.at(l)).at(pos)-sum.at(yoko.at(l-1)).at(j)+sum.at(yoko.at(l-1)).at(pos)>k) [ok = false ;if(j==pos+1) subcnt = 10000 ;}
      |                                                                                                                                                                       ^
a.cc: In function 'int main()':
a.cc:108:29: error: 'ok' was not declared in this scope; did you mean 'k'?
  108 |                         if(!ok){
      |                             ^~
      |                             k
a.cc:109:39: error: 'j' was not declared in this scope
  109 |                                 pos = j-1 ;
      |                                       ^
a.cc:114:24: error: 'sub' was not declared in this scope; did you mean 'sum'?
  114 |                 if(ans>sub+subcnt) ans = sub+subcnt ;
      |                        ^~~
      |                        sum
a.cc:114:28: error: 'subcnt' was not declared in this scope
  114 |                 if(ans>sub+subcnt) ans = sub+subcnt ;
      |                            ^~~~~~
a.cc: At global scope:
a.cc:117:9: error: 'cout' does not name a type
  117 |         cout << ans << endl ;
      |         ^~~~
a.cc:118:1: error: expected declaration before '}' token
  118 | }
      | ^