### ch_dktomar's blog

By ch_dktomar, history, 4 weeks ago,

void solve() { int n, h, a, b, k; cin >> n >> h >> a >> b >> k;

for(int i = 0; i < k; i++) {
int t1, f1, t2, f2;
cin >> t1 >> f1 >> t2 >> f2;
if(t1 == t2) {
cout << std::abs(f1 - f2) << endl;
continue;
}
const auto d1 = std::abs(f1 - a) + std::abs(a - f2);
const auto d2 = std::abs(f1 - b) + std::abs(b - f2);
cout << std::min(d1, d2) + std::abs(t1 - t2) << endl;
}

}

How can the above code fail for this problem

• -3

 » 4 weeks ago, # |   0 Auto comment: topic has been updated by ch_dktomar (previous revision, new revision, compare).
 » 4 weeks ago, # |   0 try this test case Spoiler2 5 2 4 1 1 3 2 3 
•  » » 4 weeks ago, # ^ |   0 3 is the answer I am getting.I will travel from (f3 -> f2) -> (t1 -> t2) -> (f2 -> f3)Seems to be a correct ans to me.
•  » » » 4 weeks ago, # ^ |   0 you can directly travel from tower $1$ floor $3$ to tower $2$ floor $3$, as $a = 2$ and $b = 4$
•  » » » » 4 weeks ago, # ^ |   0 Why don't I need to go to floor 2 or 4 from floor 3 of tower 1.
•  » » » » » 4 weeks ago, # ^ |   0 well the point is to minimise the number of steps you take, so