Canadian Computing Competition: 2007 Stage 1, Junior #5
A truck driver is planning to drive along the Trans-Canada highway from Vancouver to St. John's, a distance of
0, 990, 1010, 1970, 2030, 2940, 3060, 3930, 4060, 4970, 5030, 5990, 6010, 7000
but more motel locations may be added just before the trip begins.
Determine if it is possible to complete the journey if:
- the trucking company insists that the driver travels a minimum distance of
km per day, - the law sets a maximum distance of
km per day, and - each night, the driver must stay at an eligible motel (from the above list or the additional locations described below).
The driver is interested in different options when making the trip, and you are to write the program to calculate how many different options there are.
For example, if no new motel locations are added,
Input Specification
The first two lines of the input are the minimum distance
You should note that no two motels are located at the same distance from Vancouver.
Output Specification
Output the number of different ways the driver can choose the motels to make the trip, under the given constraints.
Sample Input 1
1
500
0
Sample Output 1
0
Sample Input 2
970
1030
0
Sample Output 2
1
Sample Input 3
970
1040
0
Sample Output 3
4
Sample Input 4
970
1030
1
4960
Sample Output 4
2
Comments
I'm getting TLE for case 6 and 7, idk what im doing wrong here
Hmm I tried submitting your code using pypy as it is faster but it still fails: https://dmoj.ca/submission/6985494
The intended solution for this is to use dynamic programming but you could try using deque() in your code because it has faster appends and pops.
motel = [0, 990, 1010, 1970, 2030, 2940, 3060, 3930, 4060, 4970, 5030, 5990, 6010, 7000]
Important tips:
With the new cases 6 and 7, you need to use long to store some important values instead of int, else it will get overflow and cause WA.
Thank you!! This helps a lot!
Why am I getting WA for case 6?
Also, if you don't output a new line after your total it gives you Presentation Error.
You can do the problem without recursion if that's what you are looking for.
Should have specified you needed long integers!
the new testcases added by certain pretentious people who think by adding test cases w/ long or even making 400+ testcases makes them look cool.
can they move backwards
no
What happened?
New testcases were added by xiaowuc1.
Edit: xiaowuc1 claims credit should go to d.
if A = 970 && B = 1030, doesn't that mean: 0 -> 1010 -> 2030 -> 3060 -> 4060 -> 5030 -> 6010 -> happy ending?
And the output agrees with you, there is 1 way to get there.
I guess it's time for me to get glasses