So this is not a post accussing someone but more of a post for understanding the problem.↵
↵
I was giving Codeforces 944 Div 4. I had done 5 problems but the next day it shows that the solution to my 5th problem has been hacked. I took the hack test case and when I ran it on my local machine, the answer matched the expected output but when I ran it on codeforces, it shows some deviation from the expected output.↵
↵
The code↵
~~~~~↵
↵
<spoiler summary="Code">↵
...↵
↵
void takeArrayInput(vector<ll>& arr, int l){↵
for(ll i = 1; i < l; i++){↵
cin >> arr[i];↵
}↵
}↵
↵
void print(vector<ll>& arr){↵
for(int i = 0; i < arr.size(); i++){↵
cout << arr[i] << " ";↵
}↵
↵
cout << "\n";↵
}↵
↵
void solve(){↵
ll n, k, q;↵
cin >> n >> k >> q;↵
vector<ll> a(k + 1, 0), b(k + 1, 0);↵
↵
takeArrayInput(a, k + 1);↵
takeArrayInput(b, k + 1);↵
↵
for(int i = 0; i < q; i++){↵
ll d;↵
cin >> d;↵
ll l = 0, r = k, ind = 0;↵
while(r >= l){↵
ll mid = l + (r - l) / 2;↵
if(a[mid] <= d){↵
ind = mid;↵
l = mid + 1;↵
} else r = mid - 1;↵
}↵
↵
if(a[ind] == d){↵
cout << b[ind] << " ";↵
continue;↵
}↵
↵
double dist = a[ind + 1] - a[ind];↵
double time = b[ind + 1] - b[ind];↵
↵
double speed = dist / time;↵
↵
ll timeTaken = b[ind] + (d - a[ind]) / speed;↵
cout << timeTaken << " "; ↵
↵
}↵
cout <<"\n";↵
}↵
↵
int main()↵
{↵
int T;↵
cin>>T;↵
while(T--)↵
{↵
solve();↵
}↵
return 0;↵
}↵
~~~~~↵
</spoiler>↵
↵
The Test Case↵
~~~~~↵
1↵
45 16 33↵
6 26 28 32 34 35 36 37 38 39 40 41 42 43 44 45↵
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60↵
26↵
9↵
15↵
2↵
14↵
44↵
20↵
28↵
29↵
11↵
23↵
40↵
15↵
45↵
17↵
9↵
7↵
15↵
29↵
28↵
19↵
5↵
36↵
18↵
3↵
40↵
9↵
22↵
32↵
26↵
3↵
1↵
13↵
~~~~~↵
↵
for the 4th query the answer should be 15 but my solution when ran on codeforces servers produces the answer 14.↵
↵
I know that instead of calcuating speed I could have just used dist and time in the final expression but still I want to know why my answer comes out correct on my local but is wrong on codeforces.↵
↵
Please help.↵
↵
I was giving Codeforces 944 Div 4. I had done 5 problems but the next day it shows that the solution to my 5th problem has been hacked. I took the hack test case and when I ran it on my local machine, the answer matched the expected output but when I ran it on codeforces, it shows some deviation from the expected output.↵
↵
The code↵
~~~~~↵
↵
<spoiler summary="Code">↵
...↵
↵
void takeArrayInput(vector<ll>& arr, int l){↵
for(ll i = 1; i < l; i++){↵
cin >> arr[i];↵
}↵
}↵
↵
void print(vector<ll>& arr){↵
for(int i = 0; i < arr.size(); i++){↵
cout << arr[i] << " ";↵
}↵
↵
cout << "\n";↵
}↵
↵
void solve(){↵
ll n, k, q;↵
cin >> n >> k >> q;↵
vector<ll> a(k + 1, 0), b(k + 1, 0);↵
↵
takeArrayInput(a, k + 1);↵
takeArrayInput(b, k + 1);↵
↵
for(int i = 0; i < q; i++){↵
ll d;↵
cin >> d;↵
ll l = 0, r = k, ind = 0;↵
while(r >= l){↵
ll mid = l + (r - l) / 2;↵
if(a[mid] <= d){↵
ind = mid;↵
l = mid + 1;↵
} else r = mid - 1;↵
}↵
↵
if(a[ind] == d){↵
cout << b[ind] << " ";↵
continue;↵
}↵
↵
double dist = a[ind + 1] - a[ind];↵
double time = b[ind + 1] - b[ind];↵
↵
double speed = dist / time;↵
↵
ll timeTaken = b[ind] + (d - a[ind]) / speed;↵
cout << timeTaken << " "; ↵
↵
}↵
cout <<"\n";↵
}↵
↵
int main()↵
{↵
int T;↵
cin>>T;↵
while(T--)↵
{↵
solve();↵
}↵
return 0;↵
}↵
~~~~~↵
</spoiler>↵
↵
The Test Case↵
~~~~~↵
1↵
45 16 33↵
6 26 28 32 34 35 36 37 38 39 40 41 42 43 44 45↵
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60↵
26↵
9↵
15↵
2↵
14↵
44↵
20↵
28↵
29↵
11↵
23↵
40↵
15↵
45↵
17↵
9↵
7↵
15↵
29↵
28↵
19↵
5↵
36↵
18↵
3↵
40↵
9↵
22↵
32↵
26↵
3↵
1↵
13↵
~~~~~↵
↵
for the 4th query the answer should be 15 but my solution when ran on codeforces servers produces the answer 14.↵
↵
I know that instead of calcuating speed I could have just used dist and time in the final expression but still I want to know why my answer comes out correct on my local but is wrong on codeforces.↵
↵
Please help.↵