1569C — Jury Meeting: Not able to calculate n! — (n!/(k+1)

Revision en1, by ProveMeRight, 2023-07-30 09:45:54

According to the solution, I need to calculate n! — (n!/(k+1).

I tried two ideas to calculate this but still got the wrong answer on Test 2

216215234 for the idea:

val = (fact[n] * inv(cnt+1))%mod

cout << fact[n] - val << endl;

216404434

int val = fact[n]/(cnt+1);

cout << fact[n] - val << endl;

Please help, as I'm stuck on this since yesterday.

void solve() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, 0, n) cin >> v[i];
  sort(all(v));
  if (v[n - 1] == v[n - 2])
  {
    cout << fact[n] << endl;
    return;
  }
  int cnt = count(all(v),v[n-1]-1);
  int val = (fact[n] * inv(cnt+1))%mod
  cout << fact[n] - val << endl;
}

Note: In my template, I defined int as a long long, and pre-computed fact array.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ProveMeRight 2023-07-30 09:45:54 896 Initial revision (published)