Afifii's blog

By Afifii, history, 7 years ago, In English

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

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it