Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    h, w, k = map(int, input().split())
    s = np.array([[int(i) for i in list(input())] for _ in range(h)])
    cnt = [bin(i).count("1") for i in range(2**(h - 1))]
    for i in range(2**(h - 1)):
        ss = np.split(s, [j + 1 for j in range(h - 1) if i & 2**j])
        stack = np.zeros(cnt[i] + 1, dtype=int)
        for j in range(w):
            sm = [st.T[j].sum() for st in ss]
            if max(sm) > k:
                cnt[i] = 100000
                break
            for t, st in enumerate(sm):
                stack[t] += st
            if max(stack) > k:
                for t, st in enumerate(sm):
                    stack[t] = st
                cnt[i] += 1
    print(min(cnt))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    h, w, k = map(int, input().split())
    s = [[int(i) for i in list(input())] for _ in range(h)]
    cnt = [bin(i).count("1") for i in range(2**(h - 1))]
    c = 0
    for ci in [sum(i) for i in zip(*s)]:
        if ci > k:
            cnt[0] = 100000
            break
        c += ci
        if c > k:
            cnt[0] += 1
            c = ci
    for i in range(1, 2**(h - 1)):
        div = [j + 1 for j in range(h) if i & 2**j]
        ss = []
        l = 0
        for d in div:
            ss.append(s[l:d])
            l = d
        ss.append(s[l:])
        c = [0] * len(ss)
        t = [[sum(i) for i in zip(*si)] for si in ss]
        for j in range(w):
            if max(ti[j] for ti in t) > k:
                cnt[i] = 100000
                break
            for tt, ti in enumerate(t):
                c[tt] += ti[j]
            if max(c) > k:
                cnt[i] += 1
                c = [ti[j] for ti in t]
    print(min(cnt))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np

def main():
    h, w, k = map(int, input().split())
    s = np.array([[int(i) for i in list(input())] for _ in range(h)])
    cnt = [0] * 2**(h - 1)
    for i in range(2**(h - 1)):
        ss = np.split(s, [i & 2**j for j in range(h - 1) if i & 2**j > 0])
        cnt[i] += bin(i).count("1")
        l = 0
        for j in range(1, w + 1):
            if max(si[:, l:j].sum() for si in ss) > k:
                l = j - 1
                cnt[i] += 1
    print(min(cnt))

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    h, w, k = map(int, input().split())
    s = [[int(i) for i in list(input())] for _ in range(h)]
    cnt = [bin(i).count("1") for i in range(2**(h - 1))]
    c = 0
    for ci in [sum(i) for i in zip(*s)]:
        if ci > k:
            cnt[0] = 100000
            break
        c += ci
        if c > k:
            cnt[0] += 1
            c = ci
    for i in range(1, 2**(h - 1)):
        div = [j + 1 for j in range(h) if i & 2**j]
        ss = []
        l = 0
        for d in div:
            ss.append(s[l:d])
            l = d
        ss.append(s[l:])
        c = [0] * len(ss)
        t = [[sum(i) for i in zip(*si)] for si in ss]
        for j in range(w):
            if max(ti[j] for ti in t) > k:
                cnt[i] = 100000
                break
            for tt, ti in enumerate(t):
                c[tt] += ti[j]
            if max(c) > k:
                cnt[i] += 1
                c = [ti[j] for ti in t]
    print(min(cnt))

if __name__ == '__main__':
    main()