Alkhwarizm- DIVIDE and RULE

why my solution giving wrong answer, i have checked some accepted code algo seems to correct. here my code.

main()
  {
ll T;

cin>>T;
while(T–) {

	ll n,x,y;
	bool posx[100001],negx[100001];
	bool posy[100001],negy[100001];
	memset(posx,0,sizeof(posx));
	memset(negx,0,sizeof(negx));
	memset(posy,0,sizeof(posy));
	memset(negy,0,sizeof(negy));
	cin>>n;
	ll resx,resy;
	resx=0;
	resy=0;
	for(ll i=0;i<n;i++){
		cin>>x>>y;
		 if(x<0){
		 	x=x*(-1);
		 	if(negx[x]==0){
		 		resx++;
		 		negx[x]=1;
		 	}
		 }
		 if(y<0){
		 	y=y*(-1);
		 	if(negy[y]==0){
		 	resy++;
		 	negy[y]=1;
		 }
		 }
		 if(x>=0){
		 	if(posx[x]==0){
		 	resx++;
		 posx[x]=1;	
		 }
		 }
		 if(y>=0){
		 	if(posy[y]==0){
		 	resy++;
		 	posy[y]=1;
		 }
		 }
	
	}
	if(n==0){
cout<<"0"<<endl;//I have also test code when n=0 and print 1//it was also giving wrong answer
	}
	else{
	ll res=(resx+1)*(resy+1);
 	cout<<res<<endl;
    }

}

}

1 Like

if(n==0) the answer will be 1, because there is one partition exist.

i had also tested with it. but it was also giving wrong answer.

Also i think that the if conditions don’t work right. If x<0, then you change sign of x. So if(x>=0) will be done also. In other words, you will get resx+=2, but resx+=1 is correct. The same situation with y.

thanks got it.
i thought there might be some corner case or something else i was missing.i struggled around 1-1.5 hour yesterday .now it works fine… thanks again…