HUNGALGO problem

I don’t know what’s wrong in this code please someone help me.

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

int main() {

int t;
cin>>t;
while(t--)
{
    int n;
    cin>>n;
    int a[502*502],r[n]={1},flag=1,c[n]={1};
    for(int i=0;i<n*n;i++)
    {
    scanf("%d",a[i]);
    if(a[i]==0)
            {
              r[i%n]=0;
              c[i%n]=0;

              }
  	    }


      for(int i=0;i<n;i++)
      if(r[i]==1 || c[i]==1)
      {flag=0;
      break;
      }

      if(flag==1)
    printf("YES");
    else
    printf("NO");
}
return 0;

}

I did not read your complete code but you might wanna recheck the declaration r[n] = {1} as in case of r[n] = {0} this type of declaration works because the first element is given the value mentioned in the brackets i.e ‘0’ and the rest are assigned with zero.
but in case of r[n] = {1} it will not work as the first element is assigned 1 but the rest of the elements are again initialized with ‘0’.

here is an example code:

int r[10] = {1} ;
    FOR(i, 0, 10) std::cout << r[i] << " " ;
 // returns 1 0 0 0 0 0 0 0 0 0
// not      1 1 1 1 1 1 1 1 1 1

Point to remember: Any element which is not explicitly initialized will be always assigned a zero value.

Read More

thanks bro for this info. actually ,i’m new to programming that’s why i’m facing difficulties.if you don’t mind please make changes in my code so that it can run.i’ll learn something new from you by this…

1 Like

i made slight changes in your code . check here - https://www.codechef.com/viewsolution/24073989

@shivamchef thanks buddy!