Why STL implementation is not getting accepted

Question Link : WALKFAST Problem - CodeChef
I was trying to solve the above mentioned question. But because of logical error it was not accepted. After few trial I looked into the submissions of other people. Which was accepted.
Copied Solution link : CodeChef: Practical coding for everyone
Link of submission made by me
link1 : CodeChef: Practical coding for everyone (my code with same logic only difference is using vector instead of array not accepted)
link2 : CodeChef: Practical coding for everyone (@sachin_4099 code with vector not accepted)

Link of submission which is accepted without use of vector
link : CodeChef: Practical coding for everyone

Please explain why I am getting wrong answer or run time error when I am using vector in place general array. I tried many times but every time the solution was rejected. Explain the fault in my code whose link is mentioned above. Link of whole submission of FASTWALK is : CodeChef: Practical coding for everyone

That’s not the only difference: in your vector version, you have:

(abs(arr.at(c)-arr.at(d)*q)

which is different to your array version:

(abs(arr[c]-arr[d])*q)

Edit:

While I’m at it - there’s really no good reason to use std::vector::at instead of std::vector::operator[] in CP (it’s just slower for no benefit), and there’s no need to clear() a vector that is about to go out of scope :slight_smile:

3 Likes

Thanks for your(@ssjgz ) support. That was my mistake. Explain one more thing. What is the meaning of
int arr[320]{0};
Thank you again

1 Like

It’s an array of 320 ints, all of which are initially 0.

1 Like