QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22490. Kuhfotografien

Statistics

Farmer John will seine ganze Herde $N$, $1 \le N \le 100,000$, Nummern $1..N$, fotografieren, um Freunden zu imponieren.

Am Fototag laufen die Kühe und bilden eine beliebige Reihe, Position $i$ mit $c_{i}$, $1 \le c_{i} \le N$. Er hat eigene Ordnungsideen.

FJ meint: Kuh $i$ darf nur links von $i+1$ stehen für alle $i$, $1 \le i \le N-1$, und $N$ nur links von $1$. Natürlich steht niemand links der ersten, äußersten linken Kuh.

Hungrig warten sie aufs versprochene Essen nach dem Foto. Er will schnell fertig sein. Anweisungen folgen sie schlecht: Ein Nachbarpaar darf einmal je Minute tauschen. Wie schnell entsteht eine akzeptable Ordnung?

Fünf Kühe anfangs:

     Links           Rechts
        3  5  4  2  1

Erst das zweite Paar tauschen:

        3  4  5  2 1

Dann das äußerste rechte:

        3  4  5  1  2

Eine passende Ordnung in nur zwei Tauschminuten.

Eingabe

  • Zeile $1$: eine ganze Zahl $N$.

  • Zeilen $2..N+1$: Zeile $i+1$, Nummer $c_{i}$ der $i$-ten Kuh.

Ausgabe

  • Zeile $1$: minimale Zeit in Minuten zur passenden Ordnung.

Beispiele

Eingabe 1

5
3
5
4
2
1

Ausgabe 1

2

Hinweis

Aufgabenautor: Travis, 2010

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.