DCE05: Getting wa

#include<stdio.h>
#include<stdlib.h>

int main()
{
  unsigned t=0,i,j,b=0;
  scanf("%u",&t);
  if(t<=1000000)
  {
	unsigned a[t];
   for(i=0;i<t;i++)
  {
   scanf("%u",&a[i]);
   if(a[i]>1000000000)
   {
	   j=-1;
	   break;
   }
  }
  if(j!=-1)
  {
  for(i=0;i<t;i++)
  {
   for(j=1;;j=j*2)
   {   b=2*j;
	   if(a[i]==1||a[i]==0)
	   {
		printf("%u\n",a[i]);
		break;
	   }
	   else if(a[i]>=j&&a[i]<b)
		{
		  printf("%u\n",j);
		 break;
		}

   }

	}

}
return 0;
}
}

it seems, that problem is in the conditions, it seems there is t > 10^6 or n > 10^9, your solution works fine when you remove your conditions…

@admin can you check the inputs?

1 Like

evil_prince:

Your logic and solution for the problem http://www.codechef.com/problems/DCE05/ is absolutely perfect,infact for this particular problem ,there is something wrong with the judge or may be test -data(as @betlista pointed out) or may be both.

I can’t believe, the above code gives correct answer in C++ 4.0.0-8 compiler

But gives wrong answer in C++ 4.3.2,C99 strict,C-4.3.2.

I have n’t encountered this before in code-chef.

As far as I know,the official input test file for all languages is same,then why is this happening?

@admin::Please have a look at this.

2 Likes

please use the code option from toolbar - http://i.imgur.com/ODZlB.png (you can edit your question)

@betlista: The submission ID link that u posted doesn’t contain the exact solution/code of @evil_prince(Especially this line printf(“sizeof unsigned: %d\n”, sizeof(unsigned) );,which i think u added for purpose of debugging makes the huge difference).
What I mean is -You just COPY the code of @evil_prince which he had posted above and then compile it with c++ 4.0.0-8.

I just copied @evil_prince code,and compiled it with c++ 4.0.0-8 and it gives correct answer.Check this http://www.codechef.com/viewsolution/1059991 So ,I thnk I am absolutely correct :slight_smile:

1 Like

@ritesh_gupta: you are right, I’m sorry :wink: