#133

Hello,
First and foremost, The problem is really interesting and keep on innovating.

Although, I was able to pass only 7 test cases, I’m curious to know the algorithm.
So, can you please tell me the way you have constructed.

Keep Innovating

Thank you

Here’s my code; I someone can help me to figure out the bug, please!

``````// the program below works fine
// for all test cases except
// Test Cases: 6,9,10
// Reason: for 6; output: 48 but answer:49
// Reason: for 9; output: 0 but answer:6
// Reason: for 10; output: 88 but answer: 74

import sys
import math

//max_speed_original km/h
max_speed_o = int(input())
light_count = int(input())

// max_speed m/s
max_speed = max_speed_o * 5/18

dur = []  //duration
dist = [] //distance

// store the values in a list
for i in range(light_count):
distance, duration = [int(j) for j in input().split()]

dur.append(duration)
dist.append(distance)

// min time for the closest light
t_min_i = dist[0]/max_speed

// approx int val
t = math.floor(t_min_i)

while True:
isGreen = False

#iterate through each
for i in range(light_count):

// using point slope method to find the intercept
if int((dist[i]/dist[0]*t)//dur[i]) % 2 == 0:
isGreen = True
else:
isGreen = False
break

if isGreen:break
t += 1

if isGreen:

//s = speed
s = (dist[0]/t)

// check if speed > max_speed m/s
s = max_speed if s>max_speed else s

//print('Floor km/h:',math.floor(s* (18/5)))

s = math.floor(s* (18/5))

// check if speed > max_speed km/h
s = max_speed_o if s>max_speed_o else s

print(s)
//-----------End -----------``````

#134

well, from third attempt I hacked through it: the problem is that condition “you can’t cross light on the second it turns red” does not define precision of time, i.e. if you reach light at e.g. time=14.9999998s tests could count it as 15s. Maybe it is just implementation problem of the tests.
In fact, it seems that actual challenge is not (only) to solve the task, but to get over the non precise requirements

#135

No, the challenge is to find how to solve it without rouding issues so you don’t accuse the game instead of accusing your solution.

#136

Thanks. I didn’t read carefully and got only 2 tests right because I thought the distance to next light was in the same unit as the speed.

#137

I’m confused, I can’t solve the second testcase. I have tried doing unit conversions, which just give me the exact same result. I exported some variables:
Distance: 200
Speed Limit: 50
Arrival Time: 4
Duration: 10
Ideal Speed: 50
It says expected was 36km/h. But if the Duration was 10 seconds, and I get there in 4, how would 36 be considered the answer?

#138

4 seconds to travel 200 meters.

If I’m not mistaken, that’s 50 meters per second. So 3 km / minute. So 180km / hour

That’s fast

#139

#140

Hi, I am new in this site. I want working with this site but i cannot becouse i am not understanding. please help me. thenks.

#141

You are given:
Speed - X Killometer per Hour
Distance - Meters
Duration - Seconds
So for example 10Km/H is 2.7778 ms so we will travel 200 meters in 71 Seconds…
Always read what are you given, or you will stuck with wrong data.

#142

so my program includes this specific calculation: 1.2/6.0/(1/180). When i punch it into a calculator it turns out to be 36 (which means my program works). However on codingame (I’ve tried on another puzzle), it outputs infinity instead and now I’m stuck on the light string test while having passed all but another test. Is this a problem on my side?

#143

Hello! Need your help. Who knows what example 10 test?

#144

With the expression (1/180) you are dividing two integers, and the result will also be an integer. (1/180) will evaluate to an integer value 0.

Replace it with (1.0/180.0) and it will probably work.

#145

how can i ask my question
i have a doubt in this puzzle
if speed is already given what is needed to be done

#146

i don’t understand anything

#147

the puzzle says to output the maximum speed but the outputs are the same or less than the riginal speed pls explain

#148

The goal is to find the maximum speed (off speeding) that will allow you to cross all the traffic lights to green.

At maximum speed, you’ll probably pass a traffic light while it’s red. That’s why you need to slow down so you pass all traffic lights to green.

#149

Dear all,

I passed all the tests except the last one with 100 lamps.
In this last case for the supposedly “winner speed” given in the solution my method gives only 86 green lamps out of 100. I wonder why?
I convert the initial int value of distance into double type km and the duration in double type hour value.
My method in Java:
The “outer” loop, which is already given, is that of the lamps.
I create an array speed[] which represents all the int speeds from 1 to max. speed (all the values of this array are 0 at the beginning, only the indexes “show” the speed, not their value), and with the “inner” loop I go through all the speeds for each lamp. If the lamp is green for the speed “z” then speed[z] increases with 1.
Whether a lamp is green upon the arrival of the car, I calculate like this.

1. If speed X duration ≥ distance, then its ok, green.
2. z is an even integer increasing in a loop (2, 4, 6, etc). If z X speed X duration < distance and distance < (z+1) X speed X duration, also then its green.

At the end I search for the biggest value in speed[] starting from max speed going backward to the lowest.
Where can there be a mistake?

#151

I am just about to begin solving this challenge. At first I thought I understood the problem but printing out some test cases got me very confused. Perhaps I am a little thick today, I am finding it hard to understand the problem even though I am a native english speaker.

In test case 1, distance to the traffic light is 200m and the light switches every 15 sec. The answer is 50 km/hr because anything less than this it will be unable to cross the light before it tuns red (by the way, shouldn’t it be 48 km/hr?).

But in test case 2, distance to traffic light remains the same but the period of light switching reduces to 10 sec. Shouldn’t the speed then be greater than 50km/hr? How is it the answer is 36? Kindly help.

#152

Because the maximum allowed speed for test case 2 = 50 => can not cross the light in 1st duration (green) => coss the light in [2k,(2k+1)] * duration
speed = 36km/h = 10m/s => After 10s green + 10s red => 10 *20 = 200 = distance. But i think 20th second is still in red duration. I passed this test but when i submit it failed
sorry for my english

#153

You don’t have to pass the light before it turns red. You have to pass the light when it is green.

In other words, it is allowed for the light to turn red, as long as it is green again when you pass it.