Hmm, if you use an array of (unsigned) chars instead of an array of 'booleans', you only need to initialise once in every 256 cases; not that it will save you much time, I think.
I agree with the previous posts that avoiding the extreme cases in the actual input for this problem, makes it misleading. The problem would be better off with a lower, but 'do-able in worst cases' limit. Unless, of course, there is an algo that needs less than O(N) function evaluations.
11036 - Eventually Periodic Sequence
Moderator: Board moderators
-
- Learning poster
- Posts: 99
- Joined: Sun Apr 06, 2003 5:53 am
- Location: Dhaka, Bangladesh
- Contact:
Hi,
Thanks to mf for mentioning the Floyd's Algorithm. It was really a nice algo and I have just got AC .. but the timing came really bad (about 4 sec). I had a few questions:
1. Well .. according to wiki .. I made two iterations and calculated the GCD to get the actual period. Is there any better way of doing it??
2. I used a stack (of integers) to evaluate the function. But is there any faster way???
Thnx in advance
Thanks to mf for mentioning the Floyd's Algorithm. It was really a nice algo and I have just got AC .. but the timing came really bad (about 4 sec). I had a few questions:
1. Well .. according to wiki .. I made two iterations and calculated the GCD to get the actual period. Is there any better way of doing it??
2. I used a stack (of integers) to evaluate the function. But is there any faster way???
Thnx in advance
Where's the "Any" key?
Can't find the problem.
Getting WA on this code:
Can't figure out where it's wrong, and example runs fine,
plus all i can think of, so looking for failed test-case.
Code: Select all
// AC
plus all i can think of, so looking for failed test-case.
Last edited by Ecou on Fri Aug 11, 2006 10:53 am, edited 1 time in total.
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: Can't find the problem.
Try the following input:Ecou wrote:Can't figure out where it's wrong, and example runs fine,
plus all i can think of, so looking for failed test-case.
Code: Select all
11000000 10999998 x x x x * * * N %
0 0 0 N %
Code: Select all
1250
Last edited by Martin Macko on Fri Aug 11, 2006 10:49 am, edited 2 times in total.
-
- A great helper
- Posts: 481
- Joined: Sun Jun 19, 2005 1:18 am
- Location: European Union (Slovak Republic)
Re: Thanks.
Ups, sorryEcou wrote:Thanks, fixed. I forgot to modulo after each operation.
PS: If you read this for testcases, the above is not like promised because of n > N.

And btw, please, remove your code after having accepted.