My code for the problem passed the last 3 test cases but i dont know if my approach is 100% correct or not.If someone could help me out to debug the code or tell if this approach wont get me the right answer then it would be really helpfull
heres 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>& 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 d = sqrt(area);
int rest = min(k, ones);
int ans = area + rest;
cout << ans / d << "\n";
}
return 0;
}
’ ’ ’