TripProblem code: TRIP |
All submissions for this problem are available.
You are starting out on a long (really long) trip. On the way, there are N gas stations, the locations of which are given as a_1,a_2,...,a_N. Initially you are located at the gas station at a_1, and your destination is at location a_N. Your car can only store enough fuel to travel atmost M units without refilling. You can stop at any station and refill the car by any amount. Now you wish to plan your trip such that the number of intermediate stops needed to reach the destination is minimum, and also how many ways are there to plan your trip accordingly.
Input :
The first line two space seperated integers N and M. N lines follow, and the ith line has the value a_i (0 <= a_i <= 1000000000). The input will be such that a solution will always exist.Output :
Output two space seperated integers : The least number of stops, and the number of ways to plan the trip which uses the least number of stops. Output this value modulo 1000000007.Sample Input :
6 3 0 1 3 4 7 10
Sample Output :
3 2
Constraints :
2 <= N <= 1000000 1 <= M <= 1000 a_1 < a_2 < .. < a_N
| Date: | 2010-03-20 |
| Time limit: | 2s |
| Source limit: | 50000 |
| Languages: | C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK JS |
Comments

Fetching successful submissions

1) Are the locations a_i
1) Are the locations a_i guaranteed to be unique?
2) Are the a_i guaranteed to be in sorted order (i.e. a_1 <= a_2 <= a_3 <= ... <= a_N)?
@Chris Please read the
@Chris Please read the Constraints.
My test program in Python
My test program in Python gives the error: ":( internal error occurred in the system"
Obviously it doesn't happen to everybody... is it because I'm using Python?
@John Please check the 'My
@John Please check the 'My Submissions' page for the result. There is an issue with this and we are working on it.
OK, thanks. This time I got
OK, thanks. This time I got TLE.
What does i represent in the
What does i represent in the test cases?
does the number of stops also
does the number of stops also include initial position and the final destination??
@Brien: i represents each
@Brien: i represents each number from 1 to N.
@vishal: The problem statement says intermediate stops.
getting "time limit exceeded"
getting "time limit exceeded" but
the memory(MEM) i use is displayed to be 0
but when i got "runtime error"
with the same code (except that i mistakenly
then memory kept macro value 1000 instead of specified 1000000)
the memory usage was displayed to be 1.6M
in my submissions page.
can some codechef guy please explain this.
will u need id of the code submitted ?
221394-Time limit exceeded
221379-RunTime error
@ everyone i am getting
@ everyone
i am getting runtime error in this one...i have made the program n have tested many times n its working perfect.. i don't know what to do..I also read the FAQ but still don't know how to remove it..I am a amateur so plz suggest things which should i check to remove this error..Also do we have to do modulos 10000000007 only for no. of different paths obtained??
If you want help you'll need
If you want help you'll need to wait until after the contest. Please don't ask for help during the contest. The output format is pretty clear over what to output.
plz answer my
plz answer my query..CODECHEF
i am writing it again here:
getting "time limit exceeded" but
the memory(MEM) i use is displayed to be 0
but when i got "runtime error"
with the same code (except that i mistakenly
then memory kept macro value 1000 instead of specified 1000000)
the memory usage was displayed to be 1.6M
in my submissions page.
can some codechef guy please explain this.
will u need id of the code submitted ?
221394-Time limit exceeded
221379-RunTime error
As far as I'm aware the
As far as I'm aware the memory usage is normally shown as 0 if you get time limit exceeded on the first input file. Probably due to the internal workings of the judge.
That's bug similar to what in
That's bug similar to what in the SPOJ system as CodeChef uses SPOJ engine.
So the answer is, the memory is only guaranteed to be (approximately) correct if you program is correct. If you program malfunctions in some way, the memory shown may not tell anything.
does everytime given input
does everytime given input will provide enough value of m so that the car reaches the destination,for example
4 2
1
4
6
7
what should be output
That is specifically
That is specifically mentioned in the 'Input' section.
thanx u Stephen Merriman
thanx u Stephen Merriman
My algo is O(mn) time
My algo is O(mn) time complexity algo.. still TLE,
PLzzzz tell me how much more, must i simplify.
I've checked that ,only for taking inputs , my program
is taking 1.21 seconds :(, I'm confused how others
have done in less than this tym ..
plzzzzzzzzz help
ofcourse it will TLE. mn =
ofcourse it will TLE. mn = 10^9 , which is huge. I guess we can do around 10^7 to 10^8 computations in one second. So, come up with better methods.
the number in each station is
the number in each station is the amount of fuel that it has available ?
@Anil kishore, i've submiited
@Anil kishore, i've submiited a code which was just taking inputs m and n ,
and then n values i.se. the locations , the time taken by it was 1.21 sec,
how to reduce dat????help plzzzzzz.
@gurpreet: Simple. If reading
@gurpreet: Simple. If reading input itself is taking 1.21s and time limit is 2s, then come up with a method that can solve in better than 0.79s :)
.
@German Gonzalez: No. These are the positions of the stations. Read problem statement and constraints carefully.
@Anil Kishore , But i can see
@Anil Kishore , But i can see the AC solns which take much less than 1.21 sec
and my code takes 1.21sec only for taking inputs :)...
Well you can find out how
Well you can find out how they do it after the contest ends :) You won't get any hints in the meantime.
@gurpreet: ya, but there are
@gurpreet: ya, but there are 1.79s, 1.98s etc., also. Don't worry about, 'people might be using better i/o methods'. scanf & printf should be fine here to get AC. Make your algo better ! More details after contest.. if you are not getting it then.
@Anil kishore, Thnx for
Seriously, how can i be
Seriously, how can i be getting a compile error. The site won't cite a source of error at all and the program runs fine on my computer.
Can someone who does java point out the format of the IO? I've named my program Main and haven't imported any weird packages. Note: This isn't digging for hints. I just need to know why it isn't compiling.
@Tedrick, you can look at
@Tedrick,
you can look at some of the java solution submitted here
http://www.codechef.com/problems/INTEST
All the solution submitted for that question are public.
Ah, nevermind. I followed all
Ah, nevermind. I followed all the directions as indicated in the test program.
The real problem is that their compiler yells at me when i have import statements, which is baffling.
importing everything via java.bla.bla is simply slow
Comment edited by Admin.
Comment edited by Admin.
Comment edited by Admin.
Comment edited by Admin.
@ Vikrant discussing test
@ Vikrant discussing test cases is against the rules of the contest. Please do not do so.
@Vikrant: sure, after the
@Vikrant: sure, after the contest ends. All we can say is the obvious thing, m*n = 10^9, which is huge.. and you HAVE to get something much better than that. Please do not ask same questions again and do read all comments above.
@ all,for n=2, o/p must be 0
@ all,for n=2, o/p must be 0 1 ????
plz help......
with no penalty for wrong
with no penalty for wrong submissions, you can check that out yourself easily. Question asks for number of intermediate stops ( a_1 and a_N not counted ).
hi every1, i have a stupid
hi every1,
i have a stupid question that value of n can be 1000000 that mean to store all that values of a_N i have to declare a array[1000000] now my compiler do not allow that so ur thoughts....
I'm afraid you won't get any
I'm afraid you won't get any hints during the contest. If you still can't figure it out, you'll be able to get help after the contest finishes.
A sigh of relief...... wasted
Comment edited by Admin
Comment edited by Admin
Posting test cases is against
Posting test cases is against the rules of the contest.
The above comment is not
The above comment is not mine. Someone has written it using my name. What a loser, Grow up please!
@admins - Could you please take care of the spammer? Thanks.
@Stephen - I've myself expressed concern in the past about people putting up test cases. He/she maybe some hurt soul :-)
@admins - To prevent such
@admins - To prevent such miscreats from ruining the sanctity of Codechef, please add user's ID next to the name.
Also my name appears with the
Also my name appears with the middle name "Singh" while posting comments, which the miscreant couldn't figure out.
To be fair, there are about
To be fair, there are about 35 people on facebook with the name Gagandeep Bhatia (including 10 with middle name Singh), so I wouldn't be too quick in accusing ;)
LOL. Touche! Being too vocal
LOL. Touche!
Being too vocal about enforcing policies tends to get you on the bad side of few. But heh, I'm still in favor for penalising those putting up test cases, thoughts, approaches etc.
@Gagandeep : The user id of
@Gagandeep : The user id of the person who posted the test case is Idiotsid
The name that it has been registered by is Gagandeep Bhatia.
The user id Idiotsid will bve banned if a test case is posted again.
I don't know if there are
I don't know if there are just problems on codechef right now, or in the submission sever...
in order to figure out why I was getting TLE, I started putting a division by 0 in the code. I kept moving it up, and up... and now its the first line of main(), and the program still TLE's.... Isn't that supposed to give me a runtime error??
@Stephen Merriman can u
@Stephen Merriman
can u please send me the code of Adding Fractions and Trip at vishalguptamsp@gmail.com ..
I would be ever thankful to you...
Problem solutions for april
Problem solutions for april contest not available.
can anybody please explain
can anybody please explain the algo behind this problem.....
thanx in advance....plsss help
can anybody please explain
can anybody please explain the algo behind this problem.....
thanx in advance....plsss help
The test cases of this
The test cases of this problem are not good enough. Some programs with wrong algos have been accepted. I tried out a program in C from the visible solutions which ran for 1.13 sec. and got accepted in the pracitice section, but its logic is completely wrong!!
@admin : How do i get the
@admin : How do i get the algo of the problem?
U see it tough to get the algo from solutions. Problem creater ought to write an algo.
After the contest is over , no one takes interest in writing an algo if requested.
This would be a great help. :)
Plz any1 give me an algo of this problem..
Have you read this (which was
Have you read this (which was talked about in the blog article about this contest)?
I requested admin(codechef)
I requested admin(codechef) to
Please check the solution submitted by the muke(user name).
This will give wrong output for the input
Input:
6 3
0
1
4
5
8
9
according to me the output should be 4 1
but the program is giving the output 3 2
Please respond soon.
@Rohit Gupta The program is
@Rohit Gupta
The program is right.
The minimum no. of intermediate stops needed are 4 - (1,4,5,8) and thats the only way to do it.
So answer 4 1. Check urself, the car has to refuel on each of these stations to reach 9 bcoz it cannot travel more than 3 units at a stretch without refueling.
@ rohit ..Yes you are right.
@ rohit ..Yes you are right. His solution is definitely wrong. Even I am surprised why that stupid solution passed.
@admin Can you please explain this? why that solution passed?
@Rohit Gupta @Mahesh Sorry, I
@Rohit Gupta @Mahesh
Sorry, I meant "THE PROGRAM IS WRONG". Infact this was the program I was talking about in my earlier comment. Thats why I said that the test cases are not good enough, else there is no reason why the program got accepted.