Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

給定一個 $(1, 2, \dots, N)$ 的排列 $P = (P_1, P_2, \dots, P_N)$。

對於一個長度為 $N - 1$ 的正整數序列 $T = (T_1, T_2, \dots, T_{N-1})$,數值 $f(T)$ 定義為以下程序的回傳值。

程序 $f(T)$

  1. $t \leftarrow 0$。
  2. 當 $P$ 尚未按升序排列時:
    • (a) $t \leftarrow t + 1$。
    • (b) 令 $S = (s_1, s_2, \dots, s_k)$ 為所有滿足 $T_i \le t$ 的索引 $i \in \{1, \dots, N - 1\}$ 按升序排列組成的序列(即 $s_1 < s_2 < \dots < s_k$)。
    • (c) 對於 $j = 1$ 到 $k$:
      • 令 $i \leftarrow s_j$。然後交換 $P_i$ 與 $P_{i+1}$。
    • (d) 若 $t \ge 10^{100}$,回傳 $10^{100}$。
  3. 回傳 $t$。

請求出在所有正整數序列 $T$ 中,$f(T)$ 的最小可能值。保證存在一個序列 $T$ 使得 $f(T) < 10^{100}$。

輸入格式

輸入以下列格式給出:

N
P_1 P_2 ... P_N
  • 所有輸入值均為整數。
  • $2 \le N \le 5000$.
  • $1 \le P_i \le N$.
  • 對於 $i \neq j$,$P_i \neq P_j$。

輸出格式

輸出答案。

範例 1

4
4 2 1 3
2

範例 2

20
15 13 7 3 4 8 16 12 2 5 1 17 11 18 9 19 20 10 6 14
39

範例說明

在第一個範例中,令 $T = (2, 1, 2)$。在 $t = 1$ 時,由於 $S = (2)$,$P$ 變為 $(4, 1, 2, 3)$。在 $t = 2$ 時,由於 $S = (1, 2, 3)$,依序進行的交換使 $P$ 變化為 $(4, 1, 2, 3) \to (1, 4, 2, 3) \to (1, 2, 4, 3) \to (1, 2, 3, 4)$。因此 $f(T) = 2$。由於不存在任何 $T$ 使得 $f(T) < 2$,故答案為 $2$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.