In a problem, when I evaluate the following expressions directly in the "main" function, the solution gets accepted.
ll sum1 = a[i] + com[n]-com[n-k] + com[i-1]-com[i-1-k];
ll sum2 = a[i] + com[n]-com[n-(k-1)] + com[i-1]-com[i-1-(k-1)];
double av1 = sum1/(double)(2*k+1);
double av2 = sum2/(double)(2*(k-1)+1);
But, when I instead use a function to evaluate the same expressions, the solution fails at test case 16.
double av1 = ValAt(i, k);
double av2 = ValAt(i, k-1);
The function:
double ValAt(int i, int k)
{
ll sum = a[i] + com[n]-com[n-k] + com[i-1]-com[i-1-k];
return sum/(double)(2*k+1);
}
Does any one have a rational explanation to this? Here are the two submissions: 28570229 , 28570252
Auto comment: topic has been updated by Afifii (previous revision, new revision, compare).
I sent your solution and got AC changing double to long double, look. I think when you are assigning av to result of function it loses some precision and when you directly assign av to result it doesn't.
So, why should I loose precision when I am returning a value from a function that has the same return type? That is the strange point. Moreover, when I declared av1 and av2 as global variables and changed their values from the function, the solution also failed!
At the beginning of section 8 expressions: