Please help me in SNSOCIAL

Can anyone tell me where i was wrong in the snackdown problem SNSOCIAL?
i tHOUGHT for about 3-4 hours.

Here is the code,

#include<iostream>
#include<algorithm>
#define FOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define MAX9(a,b,c,d,e,f,g,h,i) max((max(max(a,b),max(c,d)),max(max(e,f),max(g,h))),i);  

using namespace std;
int main()
{
	int n,t,m,s,x=0,e;
	cin>>t;
	while(t--)
	{
		s=0;
		e=0;
		cin>>n>>m;
		int a[502][502]={},b[502][502]={};  //CREATE A BLANKET OF 0's TO prevent garbage value reading by MAX9.
		 
		FOR1(i,n)			//INPUT
		{
			FOR1(j,m)
				cin>>a[i][j];   
		}
		}
		while(1)		//makes the loop running for n*m times
		{
		e=0;
		FOR1(i,n)        //Counting s
		{
			FOR1(j,m)
			{
				if(s%2==0)
					{
						x = MAX9(a[i-1][j-1],a[i][j-1],a[i+1][j-1],a[i-1][j],a[i+1][j],a[i-1][j+1],a[i][j+1],a[i+1][j+1],a[i][j]);
						b[i][j]=x;
						if(a[i][j]!=x)
							e++;      //WHEN e=0, that means no changes were made.
					}
				else
					{
						x = MAX9(b[i-1][j-1],b[i][j-1],b[i+1][j-1],b[i-1][j],b[i+1][j],b[i-1][j+1],b[i][j+1],b[i+1][j+1],b[i][j]);
						a[i][j]=x;
						if(b[i][j]!=x)
							e++; 
					}
			}
		}    //FOR(i,j)
		if(e==0)
			break;
		s++;	
		}			//while 1
		cout<<s<<endl;
		           //COunting complete
	}       //WHILE(t--)
	
	return 0;
}

The code you posted is syntactically incorrect - you close too many parentheses (one curly brace above the while(1)) seems to be too much) and the return 0; is aready outside of main. Is this a copy and past error? I suppose your code was compiling :wink:

Anyway, the problem you are getting a WA is probably, because your MAX9 macro is wrong: you are missing one max.

correct version:

#define MAX9(a,b,c,d,e,f,g,h,i) max(max(max(max(a,b),max(c,d)),max(max(e,f),max(g,h))),i);

hth

1 Like

max(a, max(b, max(c, max(d, max(e, max(g, max(h, i)))))));
your max macro is wrong bro !