Roller coaster P98985


pdf   zip


The technicians of a roller coaster are worried, because reading the manual of the ACME cars that have just installed they have found the following sentence: “Danger of derailment: these cars are not prepared to put up with speeds greater than 120 km/h with security”.

—Hey Paco —ask a technician to the other one— ¿ our roller coaster does not go so fast, does it?

—¿How do you want that I know it, Johnny? I am only the one that tightens the nuts. The only thing that I have is the map of the trajectory that describes the roller coaster. It is given by a polynomial p(x) of degree three in the segment [a,b]: the value p(a) is the height of the initial point, and p(b) is the height of the final point. ¿How do you want that I know what speed will go this junk?

Johny remains a while thoughtful.

—I know that the car is stopped in highest point of the roller coaster (that, by the way, it does not have to match with the extremes a or b). And I know also that, as the cars do not have motor and the rails do not do any friction against the wheels (I know it because each morning I oil them personally) happens something that they taught me in the secondary school, something about energy conservation: the gravitational potential energy mgh turns into kinetic energy 1/2mv2, or something like that. I suppose that we could calculate something...

—Yes, sure that we could —answers Paco— But it is late and in half an hour the Simpsons starts. ¿What do you think if we do it another day?


¿Are you able to discover if the installation is safe? Assume that the acceleration of gravity g in the area of the instalation of the roller coaster is 9.81 ms−2.


The input consists of a line with a number n between 1 and 2000, followed by n lines. Each line contains 7 real numbers, separated by a space. The four first numbers c3, c2, c1, c0 are the coefficients of the polynomial p(x) of degree three

p(x) = c3 x3 + c2 x2 + c1 x1 + c0

that describes the roller coaster. The following number is the mass of the car, and the other two following numbers are the extremes a and b that describe the initial point and the final point of the roller coaster.

Your program must solve two inputs as the ones described before in a time of 1 second.

Output Your program must print n lines, one line for each presented case: it must print “No problem” if the instalation is safe (that is, the car never will pass 120 km/h), and “Crash!” if the instalation is not safe.

In order to avoid rounding problems, we assure you that in all the inputs the maximal speed is less than 119.9 km/h or greater than 120.1 km/h.

Public test cases
  • Input

    -0.96 -0.75 0.03 0.17 611.45 -3.4 0.67
    0.236 -2.14 -4.38 0.499 305.94 -0.895 10.9054
    1.48 0.04 0.59 0.82 800.14 -5.28 0.76


    No problem
  • Information
    Omer Giménez
    Carlos Molina
    Original language
    Other languages
    Official solutions
    User solutions