Typo error in editorial. It should be 10e-6 instead of 10e6.
In short :
Detailed approach ::
Click to view
for __ in range(readInt()): n,s,w = readInts() v = readInts() d = readInts() p = readInts() c = readInts() t =[] carl,sumi = 0,0 for i in range(n): if d[i]==0 and p[i]>0: carl = p[i]*1.0+c[i]*1.0 if i>=1: carl -= v[i]*1.0*sum(t)*1.0 if carl<0: carl = 0 if (((carl*1.0-c[i])/v[i]*1.0)>(w*1.0/s*1.0)) and ((((carl*1.0-c[i])/v[i]*1.0)-(w*1.0/s*1.0))*1.0*v[i]>0.000001): t.append(w*1.0/s*1.0) else: t.append(carl*1.0/v[i]*1.0) t.append(w*1.0/s*1.0) elif d[i]==0 and p[i]<=0: carl = p[i]*1.0+c[i]*1.0 if carl<0: carl = 0 if i>=1: carl -= v[i]*1.0*sum(t)*1.0 if carl<0: carl = 0 if (((carl*1.0-c[i])/v[i]*1.0)>(w*1.0/s*1.0)) and ((((carl*1.0-c[i])/v[i]*1.0)-(w*1.0/s*1.0))*1.0*v[i]>0.000001): t.append(w*1.0/s*1.0) else: t.append(carl*1.0/v[i]*1.0) t.append(w*1.0/s*1.0) elif d[i]==1 and p[i]<0: carl = abs(p[i]*1.0)+c[i]*1.0 if i>=1: carl -= v[i]*1.0*sum(t)*1.0 if carl<0: carl = 0 if (((carl*1.0-c[i])/v[i]*1.0)>(w*1.0/s*1.0)) and ((((carl*1.0-c[i])/v[i]*1.0)-(w*1.0/s*1.0))*1.0*v[i]>0.000001): t.append(w*1.0/s*1.0) else: t.append(carl*1.0/v[i]*1.0) t.append(w*1.0/s*1.0) elif d[i]==1 and p[i]>=0: carl = p[i]*-1.0+c[i]*1.0 if carl<0: carl = 0 if i>=1: carl -= v[i]*1.0*sum(t)*1.0 if carl<0: carl = 0 if (((carl*1.0-c[i])/v[i]*1.0)>(w*1.0/s*1.0)) and ((((carl*1.0-c[i])/v[i]*1.0)-(w*1.0/s*1.0))*1.0*v[i]>0.000001): t.append(w*1.0/s*1.0) else: t.append(carl*1.0/v[i]*1.0) t.append(w*1.0/s*1.0) printdec(sum(t))
logic is easy but its difficult to implement.
Really felt this when I was this solving problem.
Took around 22 submissions. And ~3.5 days to solve this. And feeling which you get after seeing AC cannot be explained using words.
Please add more problems of this type in contest.
This is only difference between CF and CC.
And this question very well removed the difference.
Good Job.
@vidyut_1 @mgch @vijju123 and Team.
Happy Coding
I dont know why people are writing such a big code for this problem, while it can be done in few lines
for _ in range(int(input())):
n,s,y = [int(x) for x in input().split()]
v = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
cost = 0
for i in range(n):
if((d[i] == 0 and (p[i] + c[i] <= 0)) or (d[i] == 1 and(p[i] - c[i] >= 0))):cost += y/s
elif(d[i] == 1 and (p[i] + (cost*v[i])) - c[i] > 0): cost += y/s
elif (d[i] == 1 and (p[i]*-1 - (cost*v[i]))/v[i] - y/s > 0.000001): cost += y/s
elif (d[i] == 1 and (p[i]*-1 - (cost*v[i]))/v[i] - y/s <= 0.000001): cost += (abs((p[i] + (cost*v[i]))-c[i])) / v[i] + y/s
elif (d[i] == 0 and (p[i] - (cost*v[i])) + c[i] < 0): cost += y/s
elif(d[i] == 0 and (p[i] - (cost*v[i])) / v[i] - y/s > 0.000001): cost += y/s
elif (d[i] == 0 and (p[i] - (cost*v[i])) / v[i] - y/s <= 0.000001): cost += (((p[i] - (cost*v[i])) + c[i]) / v[i]) + y/s
#else: cose += y/s
print("%.6f" % cost)
Can someone tell me what is the problem with this
[1]. I am getting wrong answer in one test case.:)
[1]: https://www.codechef.com/viewsolution/18177938
@pavitra_ag you didn’t consider 10^-6 while writing your code.
“Chef does not get hit by a car if the minimum distance between him and any car remains greater than 10−6 at all times.”
you can see my solution.
Hi, I was unable to solve this problem in the contest. I liked the tester’s approach which is similar to my approach. I think the editorialist explanation for tester’s code is confusing. It should be "he checks the location of car’s rear when chef has reached the lane and he checks for the location of front of the car after chef moves instantly. The editorialist said that he checks for the location of rear both the time. If I understood it wrong please let me know.
Can You plz tell me where I was wrong. Here is my
[1].
Thanks in Advance !
I know I am late here but I was bit busy due to my end semester exams.
[1]: https://www.codechef.com/viewsolution/18242666
Does this get AC? Please mention that as well
Thank you so much @aryanc403. I really dont know how did that happen
Now that I think of it…seeing {10}^{6} instead of {10}^{-6} must have been hilarious for you given how much this question revolves around this number xD
@vijju123 yeah it did. Actually readInt() and readInts() function has not been written here
It’s good to see for the first time that an organiser of a contest is too active on all threads
Its okay. Though its always useful to put the approach under the “hidden tab” and give a brief description outside it.
As in-
My description for approach
Click to view
Interested ones can see code.
People will love you a lot then~ :3
thanks will edit it
Yes. I feel you xD. Even editorialist’s solution took me 8hrs to make, because of some really minute error. we are glad you liked it
PS: Look at editorialist’s solution, I tried my best to give a neat implementation
Try checking your expressions. Your code is a bit messy to read, but I feel its the conditions. Do you handle the cases as said in the editorial?
Yes. I do handle (the car has already crossed x = 0 and the car is crossing x = 0 and the car reaches x = 0 when chef crosses). Even a counter test case would be helpful. Thanks
Generating TC for this problem is a painn xD. Especially if your solution fails only on a single test case.
I dont know why people are writing such a big code for this problem, while it can be done in few lines
Its natural to feel like this. Take my stand here-
I dont know why people are writing so many if-else conditions when only 3 suffice and prove to be exhaustive. (Check editorialist solution for implementation).
Whatever strikes the guy/~girl to solve the problem.