CHFDORA - Editorial

Why I am getting time limit exceeded for the last two test cases. My python solution - Here.

can you please explain why min(N,M)<350 ?
thanks!

Because if min(n, m) > 350 then the condition n * m < 10^5 would not hold because 350 * 350 > 10 ^ 5 .

Read the editorial further and know more. I hope you know that clicking on those Arrow like things will reveal more content.

1 Like

CodeChef: Practical coding for everyone
I have implemented the same logic, still I’m getting WA in some testcases.
Please help

This is how I did in Java

  public static void main (String[]args) throws java.lang.Exception
  {
    // your code goes here
    Reader in = new Reader();
    int t = in.nextInt ();
    for (int i = 0; i < t; i++)
      {
        int r=in.nextInt();
        int c=in.nextInt();
        int[][] a=new int[r][c];
        for (int j=0;j<r;j++)
        {
            for (int k=0;k<c;k++)
            {
                a[j][k]=in.nextInt();
            }
        }
        int count=r*c;
        int ud=0;
        int lr=0;
        for (int j=1;j<r-1;j++)
        {
          if (j<r-j-1)
          {
               ud=j;
          }
          else
          {
               ud=r-j-1;
          }
          
            for (int k=1;k<c-1;k++)
            {
                if (k<c-k-1)
                {
                    lr=k;
                }
                else
                {
                    lr=c-k-1;
                }
                
                for (int q=1;q<=ud && q<=lr; q++)
                {
                    
                    
                    if (a[j][k-q]==a[j][k+q] && a[j-q][k]==a[j+q][k])
                    {
                        count++;
                    }
                    else break;
                }
            }
        }
        System.out.println(count);
      }

I just remembered, my nm(n+m) program passed with 0.03 seconds, just by auto coding the answer when an entire row is the same.
https://www.codechef.com/viewsolution/28704770

DONT PASTE CODE HERE

Why is my code giving TLE and WA ??

My code : CodeChef: Practical coding for everyone

Thanks
:slight_smile:

Merge the two while loops to remove tle, set up and side initially as 1 and loop from i=0 to i<n to get ac

thank you so much bro

if first condition is false then it dont bother 2nd one , if first condition is true then it checks for second

I tried to find the max possible range offset first and then began checking for palindromes, but it gives WA for most of the test cases.

Code: CodeChef: Practical coding for everyone

Thanks!

1 Like

I got it why it doesn’t work

consider the example
5 5
1 1 1 8 1
1 8 1 8 1
1 1 1 8 1
1 1 1 8 1
1 1 1 8 1

Observe for (2,2) for my solution:

According to my solution - I am trying to get a square first and then compare element wise (without considering the continuity)

    1  
    1  
1 1 1 8 1
    1
    1

my algorithm will compare (2,0) and (2,4) - without considering that (2,1) != (2,3) hence there is no palindrome here, but it mistakenly adds this entry as well.

-for anyone who commits the same mistake

1 Like

PLS HELP
Why my code is giving WA
https://www.codechef.com/viewsolution/34511129

i want to ask one thing , whatabout those cases in which middle element lies somewhere else for example
1 1 1 1
2 3 2 3
1 1 1 1

here the sequence can be
[1
2
1]
and
[ 3 2 3]
which will not be covered in this brute force