Signature (HELP)

I have used Brute-Force but i am not getting right answer, can anyone please tell me whats wrong…??

LINK: #include<bits/stdc++.h>#define ll long long intusing namespace std;i - Pastebin.com

#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){

ll t; cin>>t;

while(t–){

int n,m; cin>>n>>m;
int a[n][m],b[n][m];
string s;

for(int i=0;i<n;i++){
cin>>s;
for(int j=0;j<m;j++){
a[i][j] = (s[j] - ‘0’);
}
}

for(int i=0;i<n;i++){
cin>>s;
for(int j=0;j<m;j++){
b[i][j] = (s[j] - ‘0’);
}
}

int dr = -n, dc = -m;
int ans = INT_MAX, r , c, cmp, tp;

while(dr < n){
dc = -m;
while(dc < m){
tp = 0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
r = i + dr;
c = j + dc;
if(r < 0 || r > n || c < 0 || c > m){
cmp = 0;
}
else{
cmp = b[r][c];
}
if(cmp != a[i][j]){
tp++;
}
}
}

ans = min(ans,tp);
dc++;
}
dr++;
}
cout<<"ANS "<<ans<<endl;
}
return 0;
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

1 Like

Can some one also help me. I dont know where am i going wrong

First:

r>n-1 || c>m-1 As there is no index ‘n’ or ‘m’.

Second:

“”“DO NOT PRINT UNNECESSARY THINGS”""

Try removing this:

@anon71312354 Thanks i got my mistake it was due to indexing and i was printing " ANS " for debugging as input was long and it became difficult to see the output :slight_smile:

1 Like