Help to debug code for the HOLLOW problem

Can someone please help me out to resolve the errors in the code as it only passed 3 test cases:

here’s the code:

#include<bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define ll long long int

int maximalSquare(vector<vector<char>>& matrix) {

        int m = matrix.size(), n = matrix[0].size(), sz = 0, pre;
        vector<int> cur(n, 0);
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int temp = cur[j];
                if (!i || !j || matrix[i][j] == '0') {
                    cur[j] = matrix[i][j] - '0';
                } else {
                    cur[j] = min(pre, min(cur[j], cur[j - 1])) + 1;
                }
                sz = max(cur[j], sz);
                pre = temp;
            }
        }
        return sz * sz;
    }

int main() {

	fastio;

	int t;
	cin >> t;

	while(t--) {
		int n, m, k;
		cin >> n >> m >> k;
		
		int ones = 0;
		vector<vector<char>> grid(n, vector<char> (m));
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				cin >> grid[i][j];
				grid[i][j] = (grid[i][j] == '1') ? '0' : '1';
				if(grid[i][j] == '1') ones++;
			}
		}
		
		int area = maximalSquare(grid);
//		cout << "area " << area;
		int div = floor(sqrt(area));
		
		int rest = min(k, abs(ones - area));
		
		int ans = area + rest;
		
		cout << floor(ans / div) << "\n";
	}

	return 0;
}