https://codeforces.com/gym/101628/problem/G

How to solve it?

# | User | Rating |
---|---|---|

1 | tourist | 3697 |

2 | Benq | 3583 |

3 | Petr | 3522 |

4 | ecnerwala | 3467 |

5 | Radewoosh | 3466 |

6 | maroonrk | 3369 |

7 | Um_nik | 3358 |

8 | jiangly | 3330 |

9 | Miracle03 | 3314 |

10 | scott_wu | 3313 |

# | User | Contrib. |
---|---|---|

1 | 1-gon | 213 |

2 | Errichto | 189 |

3 | awoo | 188 |

4 | rng_58 | 187 |

5 | SecondThread | 186 |

6 | Um_nik | 179 |

7 | Ashishgup | 177 |

8 | maroonrk | 172 |

8 | vovuh | 172 |

8 | antontrygubO_o | 172 |

https://codeforces.com/gym/101628/problem/G

How to solve it?

↑

↓

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/15/2021 12:15:32 (g2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Let $$$a_1, a_2, ..., a_C$$$ be the separations between consecutive partners.

We need to solve for $$$\;a_1+a_2+...+a_c=N-C\;$$$ where $$$a_i\geq R\; \forall i$$$.

This is the same as $$$\;a'_1+a'_2+...+a'_c=N-C-R*C\;$$$ where $$$a'_i\geq 0\; \forall i\quad$$$ (Substituting $$$a'_i=a_i-R$$$)

Now, notice that we can arrange a particular tuple $$$(a_1,a_2,...a_C)$$$, exactly $$$N$$$ times around the table and each will be treated as a distinct way as long as this tuple is a

unique circular permutation. (Eg. (1,1,3) and (1,3,1) or (2,3,4,5) and (3,4,5,2) arenot).One special case being that if all $$$a_i$$$'s are equal (can only happen when $$$C|N$$$) then we cannot arrange $$$N$$$ times around the table but only $$$N/C$$$ times as after that we will get a repetition.

Finally, in every scenario Pixie can be seated in $$$N-C$$$ independent ways, each counted as distinct. We can just multiply the final total with $$$N-C$$$ at the very last to incorporate that.

Therefore an algorithm would be:

Note that, $$${m+C-1 \choose m}$$$ is the total number of tuples (where $$$m=N-C-R*C$$$). Out of these at most one is of type two (if C divides N) and remaining are exactly all tuples with at least two distinct values, but these are

notcircularly invarient yet. In fact we have exactly $$$C$$$ copies of each such tuple.Thus, $$$cnt_2=(N\%C==0)$$$ and $$$cnt_1=\frac{{n+C-1 \choose n}-cnt_2}{C}\;$$$. This makes the final answer simplier — $$$\;ans=\frac{{m+C-1 \choose m}*N*(N-R)}{C}\%p$$$

Example:Test Case 1$$$a_1+a_2+a_3=9-3=6,\;\; a_1,a_2\geq2\;\;\;\qquad$$$ or $$$\qquad\;\;\;a'_1+a'_2+a'_3=0,\;\; a'_1,a'_2\geq0$$$

$$$(a_1,a_2,a_3)=(2,2,2)$$$

$$$cnt_1=0$$$. no such ways.

$$$cnt_2=1$$$ comprises of $$$(2,2,2)$$$ case repeated $$$9/3=3$$$ times. $$$\therefore 1*3=3$$$ ways.

Total $$$(0+3)*(N-C)=3*6=18$$$ ways.

Test Case 2$$$a_1+a_2=10-2=8,\;\; a_1,a_2\geq1\;\;\;\qquad$$$ or $$$\qquad\;\;\;a'_1+a'_2=6,\;\; a'_1,a'_2\geq0$$$

$$$(a_1,a_2)=(1,7),(2,6),(3,5),(4,4),(5,3),(6,2),(7,1)$$$

$$$cnt_1=3$$$ comprises of $$$(1,7),(2,6),(3,5)$$$, each repeated $$$10$$$ times. $$$\therefore 3*10=30$$$ ways.

$$$cnt_2=1$$$ comprises of $$$(4,4)$$$ case repeated $$$10/2=5$$$ times. $$$\therefore 1*5=5$$$ ways.

Total $$$(30+5)*(N-C)=35*8=280$$$ ways.