Solve this 8/15 test cases passed
Created on: June 25, 2026
Answered using GPT-5.5 Thinking by Chat01
Created on: June 25, 2026
Answered using GPT-5.5 Thinking by Chat01
Solve this 8/15 test cases passed
Your failing cases are because ccw = total - cw is not valid here.
hubTransitionTimes[i] is the cost to leave hub i, no matter which adjacent hub you go to. So clockwise and counterclockwise routes do not complement each other like normal undirected edge weights.
Use this instead:
cpplong computeMinDeliveryTime(vector<int> deliverySequence, vector<int> hubTransitionTimes) { int m = hubTransitionTimes.size(); // pref[i] = sum of hubTransitionTimes[1..i], 1-based logically vector<long long> pref(m + 1, 0); for (int i = 1; i <= m; i++) { pref[i] = pref[i - 1] + hubTransitionTimes[i - 1]; } auto clockwise = [&](int from, int to) -> long long { if (from == to) return 0; if (from < to) { // from -> from+1 -> ... -> to return pref[to - 1] - pref[from - 1]; } else { // from -> ... -> m -> 1 -> ... -> to return (pref[m] - pref[from - 1]) + pref[to - 1]; } }; auto counterClockwise = [&](int from, int to) -> long long { if (from == to) return 0; if (from > to) { // from -> from-1 -> ... -> to return pref[from] - pref[to]; } else { // from -> ... -> 1 -> m -> ... -> to return pref[from] + (pref[m] - pref[to]); } }; long long ans = 0; int cur = 1; for (int dest : deliverySequence) { long long cw = clockwise(cur, dest); long long ccw = counterClockwise(cur, dest); ans += min(cw, ccw); cur = dest; } return ans; }
Also, your prefix loop has an out-of-bounds bug:
cppfor(int i = 0; i <= m; i++) prefix[i+1] = prefix[i] + hubTransitionTimes[i-1];
At i = 0, it reads hubTransitionTimes[-1]. At i = m, it reads hubTransitionTimes[m]. Both are invalid.
The corrected prefix loop is:
cppfor (int i = 1; i <= m; i++) { pref[i] = pref[i - 1] + hubTransitionTimes[i - 1]; }