公式

C - Ideal Holidays 解説 by en_translator


First of all, it only matters what day of the week it is, so we replace \(D_i\) with the remainder divided by \((A+B)\).

After applying such operations on \(D\), sort it in ascending order and remove duplicates. Let \(E=(E_1,E_2,\ldots,E_k)\) be the resulting sequence.

Then, the answer is Yes if and only if:

  • there exists \(i\ (1\leq i \leq k)\) such that \((E_{i+1}-E_i) \bmod (A+B) > B\), where \(E_{k+1}\) means \(E_1\).

The proof follows the fact that we can safely assume that \(E_i\) is the first day of the week for some \(i\) (if this is not satisfied but the condition in the problem statement is, then the latter is satisfied after shifting the first day).

This procedure runs in a total of \(\mathrm{O}(N\log N)\) time.

投稿日時:
最終更新: