CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • May Cook-Off
    • May Long 2012
    • April Cook-Off
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » April 2010 Contest » Trip

Trip

Problem code: TRIP

  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

1) Are the locations a_i

narri @ 2 Apr 2010 03:48 PM

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

i0exception @ 2 Apr 2010 04:04 PM

@Chris Please read the Constraints.

My test program in Python

jcomeau_ictx @ 2 Apr 2010 09:46 PM

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

i0exception @ 2 Apr 2010 09:48 PM

@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

jcomeau_ictx @ 2 Apr 2010 10:21 PM

OK, thanks. This time I got TLE.

What does i represent in the

brien_premachandiran @ 3 Apr 2010 05:08 AM

What does i represent in the test cases?

does the number of stops also

sankikhopadi @ 3 Apr 2010 10:00 AM

does the number of stops also include initial position and the final destination??

 

@Brien: i represents each

triplem @ 3 Apr 2010 12:08 PM

@Brien: i represents each number from 1 to N.

@vishal: The problem statement says intermediate stops.

getting "time limit exceeded"

shaurya @ 4 Apr 2010 04:36 PM

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

sankikhopadi @ 5 Apr 2010 01:47 AM

@ 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

triplem @ 5 Apr 2010 02:30 AM

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

shaurya @ 5 Apr 2010 11:41 AM

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

triplem @ 5 Apr 2010 11:57 AM

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

writerAPR10 @ 6 Apr 2010 01:04 AM

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

anshusaurav @ 6 Apr 2010 02:53 AM

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

triplem @ 6 Apr 2010 06:37 AM

That is specifically mentioned in the 'Input' section.

thanx u Stephen Merriman

shaurya @ 6 Apr 2010 03:50 PM

thanx u Stephen Merriman

  My algo is O(mn) time

gurpreet_09 @ 6 Apr 2010 05:57 PM

 

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 =

flying_ant @ 6 Apr 2010 07:30 PM

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

devwebcl @ 6 Apr 2010 09:09 PM

the number in each station is the amount of fuel that it has available ?

@Anil kishore, i've submiited

gurpreet_09 @ 7 Apr 2010 01:16 AM

@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

flying_ant @ 7 Apr 2010 08:58 AM

@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

gurpreet_09 @ 7 Apr 2010 01:03 PM

@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

triplem @ 7 Apr 2010 01:39 PM

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

flying_ant @ 7 Apr 2010 07:16 PM

@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

gurpreet_09 @ 7 Apr 2010 08:37 PM
@Anil kishore, Thnx for helping. Can u plzz tell me ur email id.I want to keep contact with you ,and get help in my programming skills :).

Seriously, how can i be

Tool @ 8 Apr 2010 01:33 AM

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

imrankane2005 @ 8 Apr 2010 01:44 AM

@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

Tool @ 8 Apr 2010 02:30 AM

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.

vikrantsingh02 @ 8 Apr 2010 04:14 AM

Comment edited by Admin.

Comment edited by Admin.

vikrantsingh02 @ 8 Apr 2010 05:28 AM

Comment edited by Admin.

@ Vikrant discussing test

triplem @ 8 Apr 2010 06:54 AM

@ Vikrant discussing test cases is against the rules of the contest. Please do not do so.

@Vikrant: sure, after the

flying_ant @ 8 Apr 2010 09:36 AM

@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

gurpreet_09 @ 8 Apr 2010 07:20 PM

@ all,for n=2, o/p must be 0 1   ????

plz help......

with no penalty for wrong

flying_ant @ 9 Apr 2010 09:05 AM

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

illusionist @ 9 Apr 2010 03:29 PM

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

triplem @ 9 Apr 2010 03:32 PM

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

gurpreet_09 @ 9 Apr 2010 03:54 PM
A sigh of relief...... wasted 2 days to find a 1 line mistake in my code, and then got AC.

Comment edited by Admin

Idiotsid @ 9 Apr 2010 07:52 PM

Comment edited by Admin

Posting test cases is against

triplem @ 10 Apr 2010 03:10 AM

Posting test cases is against the rules of the contest.

The above comment is not

gsbhatia @ 12 Apr 2010 10:46 AM

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

gsbhatia @ 12 Apr 2010 10:48 AM

@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

gsbhatia @ 12 Apr 2010 10:50 AM

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

triplem @ 12 Apr 2010 12:52 PM

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

gsbhatia @ 12 Apr 2010 01:34 PM

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

admin @ 12 Apr 2010 06:28 PM

@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

madmaxwell @ 13 Apr 2010 09:33 AM

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

vishal gupta MSP @ 13 Apr 2010 04:07 PM

@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

sjbr @ 13 Apr 2010 08:11 PM

Problem solutions for april contest not available.

can anybody please explain

dabbcomputers @ 13 Apr 2010 10:50 PM

can anybody please explain the algo behind this problem.....

thanx in advance....plsss help

can anybody please explain

dabbcomputers @ 13 Apr 2010 10:50 PM

can anybody please explain the algo behind this problem.....

thanx in advance....plsss help

The test cases of this

cybersharp @ 13 Apr 2010 11:54 PM

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

vikrantsingh02 @ 14 Apr 2010 06:57 PM

@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

triplem @ 15 Apr 2010 10:35 AM

Have you read this (which was talked about in the blog article about this contest)?

I requested admin(codechef)

code easy @ 15 Apr 2010 06:01 PM

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

cybersharp @ 15 Apr 2010 07:29 PM

@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.

mcsharma1990 @ 15 Apr 2010 11:49 PM

@ 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

cybersharp @ 16 Apr 2010 01:18 AM

@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.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com