https://www.codechef.com/submit/ADTCHP

Hey everyone, Can someone please tell why my code is not working ,To be more precise why If(x==1) is not getting executed??? And why i am getting runtime error??This is A DT chip easy problem.

#include <stdio.h>

int main(void) {
int a,b,c,x,e,f,g,h,i,j;
scanf(“%d”,&a);
scanf(“%d”,&b);
scanf(“%d”,&c);
int arr[a][b];
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
arr[i][j]=1;
}
while(c–)
{
scanf(“%d”,&x);
scanf(“%d”,&e);
scanf(“%d”,&f);
scanf(“%d”,&g);
scanf(“%d”,&h);
if(x==1)
{ printf(“yooo”);
for( i=e;i<=g;i++)
{
for(j=f;j<=h;j++)
arr[i][j]=0;

                 } 
             }
            else
                    {  
                        if(arr[e][f]==arr[g][h])
                            printf("YES\n");
                        else 
                            printf("No\n");
                    }
        }
        
return 0;

}

Although your logic is incorrect, this is what the problem with your code was :
int main(void) {
int a,b,c,x,e,f,g,h,i,j;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
int arr[a][b];
for(i=0;i<a;i++)
{
for(j=0;j<b;j++){
arr[i][j]=1;
}
}
while(c–)
{
scanf("%d",&x);
scanf("%d",&e);
scanf("%d",&f);
scanf("%d",&g);
scanf("%d",&h);
e–;
f–;
g–;
h–;
if(x==1)
{
for( i=e;i<=g;i++)
{
for(j=f;j<=h;j++)
arr[i][j]=0;

             } 
         }
        else
                {  
                    if(arr[e][f]==arr[g][h])
                        printf("YES\n");
                    else 
                        printf("No\n");
                }
    }

return 0;
}

  1. the rows/ cols are just NUMBERED from 1 to N/M, doesnt mean you can access them with the same numbers. Meaning if you define an array arr[5][5], you can still not accss arr[5][5], since the elements are indexed from 0 to 4.
    so your initial for loop to store 1 in every element is wrong.
  2. if you understand this, now you know you have to downscale every such “pointer” element, namely e, f, g, h, by 1 to be able to access them correctly.

Happy coding :slight_smile: