[Solution] NIT Destroys the Universe Codeforces Solution
For a collection of integers , define as the smallest non-negative integer that does not appear in .
NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the universe by snapping his fingers several times.
The universe can be represented as a 1-indexed array of length . When NIT snaps his fingers, he does the following operation on the array:
- He selects positive integers and such that . Let . Then, for all , set to .
We say the universe is destroyed if and only if for all , holds.
Find the minimum number of times NIT needs to snap his fingers to destroy the universe. That is, find the minimum number of operations NIT needs to perform to make all elements in the array equal to .
Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains one integer ().
The second line of each test case contains integers , , , ().
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print one integer — the answer to the problem.
No comments:
Post a Comment