Help is this problem approach right? FENCE

I am trying this approach for this problem is it
right? httpss://www.codechef.com/LRNDSA03/problems/FENCE

using namespace std;
#define ll long long
int main() {
//test case
int t;
cin>>t;
 while(t--){
     ll n,m,k;
     cin>>n>>m>>k;
     // initialising arr with '0'
     ll arr[n+1][m+1]={0};
     //marking plants with '1'
     for(int i=0;i<k;i++){
        ll a,b;
         cin>>a>>b;
         arr[a][b]=1;

     }
    //cout<<arr[5][0];
     ll ans=0;
     
     for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++){
      if(arr[i][j]==1){
        ans+=4-(arr[i+1][j]+arr[i][j+1]+arr[i-1][j]+arr[i][j-1]);
    //cout<<i<<j<<" "<<ans<<endl;
         }
     }
     }
 // cout<<ans<<endl;
 }
    return 0;
}