Page 11 of 19

Re: 488 TLE

Posted: Wed May 28, 2008 11:05 am
by Obaida
I am sending you a code by PM you better check it.
And trace the method.

Re: 488 TLE

Posted: Wed May 28, 2008 11:54 am
by hahahaken
Obaida wrote:I am sending you a code by PM you better check it.
And trace the method.
Actually mine is similar to yours and I submit my code again, still time limit exceeded
Is it related to repeatedly calling the function in my program?

Code: Select all

Removed after AC

Re: 488 TLE

Posted: Wed May 28, 2008 12:26 pm
by Obaida
Try it removing the function. Hope it will work.

Re: 488 TLE

Posted: Wed May 28, 2008 12:37 pm
by hahahaken
Obaida wrote:Try it removing the function. Hope it will work.
I have already removed the function, TLE AGAIN, NO!!!
Pls take a look at my code, I think there should be something wrong.

Code: Select all

Removed after AC

Re: 488 TLE

Posted: Wed May 28, 2008 12:44 pm
by Obaida
Those cin and cout are slow function.
Remove them and use printf and scanf.

Re: 488 TLE

Posted: Wed May 28, 2008 12:54 pm
by hahahaken
Obaida wrote:Those cin and cout are slow function.
Remove them and use printf and scanf.
The version you sent me also uses cin and cout, it's a AC, right?
Mine is not just only exceeded for a few seconds, but at least 5 - 10s, coz I keep refreshing firefox and the status keep "running" until TLE appears.
Then, the problem is that why you use cin and cout and you got correct answer but mine got TLE?

Re: 488 TLE

Posted: Wed May 28, 2008 1:14 pm
by Obaida
You should check it out, and i think it's possible for you.
So why it's me? :o

Re: 488 TLE

Posted: Thu May 29, 2008 7:42 pm
by DJWS
Obaida wrote:Those cin and cout are slow function.
Remove them and use printf and scanf.
In this problem, you can replace "endl" with "\n" and get reasonable runtime. "endl" push a character "\n" into I/O buffer and flush the buffer immediately. Frequent flushing will take a lot of time, especially with massive I/O data.

Although "endl" is somehow slower than single "\n", "endl" is not bad at all. The advantage of "endl" is that we can ensure the I/O data printing on the screen, line by line. Even though the program crashed, we still can see all messages generated by the program before the crashing. The advantage of "endl" is helpful when debugging.

BTW, cin and cout can be faster if we set up this:

Code: Select all

cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
Thus cin and cout are almost as fast as scanf and printf.

Re: 488 TLE

Posted: Fri May 30, 2008 10:43 am
by hahahaken
Finally got AC, thanks
But I want to know why the following can make my program run faster:
1. What's the difference between "endl" and "\n"?
2. What's the difference between "cin and cout" and "scanf and printf"?
3. Why "cin.sync_with_stdio(false);" and "cout.sync_with_stdio(false);" can make my program run faster?

Re: 488 TLE

Posted: Fri May 30, 2008 12:58 pm
by DJWS
hahahaken wrote:Finally got AC, thanks
But I want to know why the following can make my program run faster:
1. What's the difference between "endl" and "\n"?
2. What's the difference between "cin and cout" and "scanf and printf"?
3. Why "cin.sync_with_stdio(false);" and "cout.sync_with_stdio(false);" can make my program run faster?
They are good questions. But I cannot explain them within few words (because I am inarticulate in English). It needs deeper views about the hardware architecture and about C/C++ languages. You may google or ask others for the details. :)

Re: Crazzzzzzzzzzzzy WA...488

Posted: Mon Jun 09, 2008 10:38 pm
by newton
There would be only one test case.
You need not to handle it upto EOF.
just change
** You must avoid printing newline at the last of output.

Code: Select all

 while(scanf("%d",&n) ==1){
-------
-------
}
to

scanf("%d",&n);
------
------

Re: WA 488

Posted: Wed Jul 09, 2008 10:08 pm
by mrmrumman
Why I get wrong anser with my code what is the solution?

Code: Select all

[b]# include <stdio.h>
int main()
{
	int cases,i,height,frequency,j;
	char line;
	while(scanf("%d",&cases)==1)
        {
		for(i=0;i<cases;i++)
		{
			scanf("%d",&height);
			scanf("%d",&frequency);
			for(int l=0;l<frequency;l++)
			{
				if(l!=0)
					printf("\n\n");
				for(j=1;j<=height;j++)
				{
					for(int k=0;k<j;k++)
						printf("%d",j);
					printf("\n");
				}
				for(j=height-1;j>=1;j--)
				{
					if(j!=height-1)
						printf("\n");
					for(int k=0;k<j;k++)
						printf("%d",j);

				}

			}
		}
	
        }
	return 0;
}[/b]

Re: WA 488

Posted: Thu Jul 10, 2008 10:39 am
by mrmrumman
any1 can help why I get WA?

Code: Select all

# include <stdio.h>
int main()
{
	int cases,i,height,frequency,j;
	
	scanf("%d",&cases);
	for(i=0;i<cases;i++)
	{
		scanf("%d",&height);
		scanf("%d",&frequency);
		for(int l=0;l<frequency;l++)
		{
			if(l!=0)
				printf("\n");
			printf("\n");
			for(j=1;j<=height;j++)
			{
				for(int k=0;k<j;k++)
					printf("%d",j);
				printf("\n");
			}
			for(j=height-1;j>=1;j--)
			{
				if(j!=height-1)
					printf("\n");
				for(int k=0;k<j;k++)
					printf("%d",j);
			}
		}
	}
 	return 0;
}

Re: WA 488

Posted: Thu Jul 10, 2008 10:49 am
by emotional blind
You should not print a blank line at the very beginning.

Why WA in 488

Posted: Thu Jul 10, 2008 10:52 am
by mrmrumman
What is the problem with code any problem with my code? Is the way I taking input is right? Please help...

Code: Select all

# include <stdio.h>
int main()
{
	int cases,i,height,frequency,j;
	
	scanf("%d",&cases);
	for(i=0;i<cases;i++)
	{
		scanf("%d",&height);
		scanf("%d",&frequency);
		for(int l=0;l<frequency;l++)
		{
			if(l!=0)
				printf("\n");
			
			for(j=1;j<=height;j++)
			{
				for(int k=0;k<j;k++)
					printf("%d",j);
				printf("\n");
			}
			for(j=height-1;j>=1;j--)
			{
				if(j!=height-1)
					printf("\n");
				for(int k=0;k<j;k++)
					printf("%d",j);
			}
			printf("\n");
		}
	}
 	return 0;
}