| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 53 | 3 | 3 | 20.000% |
After spending winter break at his grandpa’s, Little Square returned home. While he was away, his friend, Little Triangle, played with his toys, numbered from 1ドル$ to $N$. In order for Little Square not to be upset with him, Little Triangle has to put his toys back in order: 1,ドル 2, \dots , N$.
Initially, all the toys are lined up on a shelf in some order.
Knowing that Little Triangle can sort a continuous interval $[i, j]$ of toys in $\lfloor \sqrt{j-i+1} \rfloor$ seconds, help him find the minimum time he can order all the toys.
The contestant must implement one function with the following signature:
int solve(int N, int P[]);
solve will be called exactly once.
The function will be supplied with $N,ドル the number of toys, and $P,ドル an array (indexed from 0ドル$) containing the initial order of the toys. It has to return an int representing the minimum time required by Little Triangle to sort all the toys.
The sample grader reads the input from standard input with the following format:
The sample grader prints the result returned by solve to the standard output.
Attention! The contestant should not implement the main function.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 7 | $P$ is randomly generated. |
| 2 | 8 | 1ドル ≤ N ≤ 9$ |
| 3 | 35 | 1ドル ≤ N ≤ 2000$ |
| 4 | 25 | 1ドル ≤ N ≤ 100000$ |
| 5 | 25 | No additional constraints. |
5 3 1 4 2 5
2
3 1 2 3
0
In the first example, Little Triangle can sort the interval $[0, 1]$ in $\lfloor \sqrt{1 - 0 + 1}\rfloor = \lfloor \sqrt{2} \rfloor = \lfloor 1.41421 \dots \rfloor = 1$ second. The permutation becomes 1ドル$ 3ドル$ 4ドル$ 2ドル$ 5ドル$. He can now sort the interval $[1, 3]$ in $\lfloor \sqrt{3-1+1} \rfloor = \lfloor \sqrt{3} \rfloor = \lfloor 1.73205 \dots \rfloor = 1$ second. The permutation becomes 1ドル$ 2ドル$ 3ドル$ 4ドル$ 5ドル$. In total Little Triangle can sort all the toys in 1ドル + 1 = 2$ seconds, which is also the minimum possible time.
In the second example, the toys are already sorted.
C++17, C++20, C++17 (Clang), C++20 (Clang)