11000 - Bee
Moderator: Board moderators
-
- New poster
- Posts: 37
- Joined: Wed Oct 03, 2007 10:42 am
Re: 11000 - Bee
Please help me. I am getting WA. my code is given bellow. I calculate fibonacci(n) and fibonacci(n +1) then subtract 1 from both of them and print.
Code: Select all
#include<stdio.h>
unsigned long a;
unsigned long fib(unsigned long n)
{
unsigned long d, b, c, i;
a = 1;
b = 1;
for(i = 1; i <= n; i ++)
{
c = a;
a += b;
b = c;
}
d = a;
a += b;
if(n == 0)
{
return 2;
}
return d;
}
int main()
{
unsigned long n;
while(scanf("%lu", &n) == 1)
{
if(n == -1)
{
break;
}
printf("%lu %lu\n",fib(n)-1, a - 1);
}
return 0;
}
Thanks;
-
- New poster
- Posts: 37
- Joined: Wed Oct 03, 2007 10:42 am
Re: 11000 - Bee
I have had a stupid mistake.
for n = 0
my solutaion gave 1 0 but it will be
0 1
Now i got accepted.
Thnx![:D](./images/smilies/icon_biggrin.gif)
for n = 0
my solutaion gave 1 0 but it will be
0 1
Now i got accepted.
Thnx
![:D](./images/smilies/icon_biggrin.gif)
Got TLE for Bee (Problem ID: 11000)!!!
Code: Select all
Got AC
Last edited by shondhi on Fri Apr 12, 2013 5:52 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Got TLE for Bee (Problem ID: 11000)!!!
Use DP to precompute the results for N<=100.
Check input and AC output for thousands of problems on uDebug!
Re: Got TLE for Bee (Problem ID: 11000)!!!
Is there another way to decrease the execution time without DP?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Got TLE for Bee (Problem ID: 11000)!!!
Memoization
Check input and AC output for thousands of problems on uDebug!
Re: Got TLE for Bee (Problem ID: 11000)!!!
Thanks, got ac..
Re: Got TLE for Bee (Problem ID: 11000)!!!
Here's some input / output I found useful during testing / debugging.
Please see https://www.udebug.com/UVa/11000 instead.
Code: Select all
Removed because the input / output was incorrect.