[BOJ 13148] Correcting Cheeseburgers

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 512M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

Cheeseburgers are serious business. They are the most delicious food on earth, but there is a lot of room for error when making a cheeseburger. Even otherwise capable cooks often mess up the order of the assembled ingredients.</p>

The only correct order of ingredients between the buns is, of course, as following from top to bottom:

  1. Ketchup & Mustard
  2. Beef Tomato
  3. Pickles
  4. Red Onions
  5. Cheddar Cheese
  6. Garlic
  7. Salt & Pepper
  8. Beef Patty, medium grilled
  9. Corn Salad
  10. Mayonnaise

Any deviation from this order is completely unacceptable. Therefore it is sometimes necessary to reassemble a cheeseburger.

Space on an average plate and social norms are rather restrictive when it comes to operating on a cheeseburger. The only feasible operation is the bit-shuffle (burger-ineptly-transformed). The bit-shuffle separates the entire burger into four parts of contiguous ingredients a, b, c and d and arranges them in the new order c a d b. The size of each of the four parts is selectable and may be zero.

Since the burger cools rapidly we are interested in the minimum required bit-shuffles to arrive at an acceptable burger.

Each given cheeseburger consists of n unique ingredients labeled from 1 to n. The correct order is always the natural order 1 2 . . . n.

Figure B.1: Illustration of the first sample input.

Figure B.2: Illustration of the second sample input.

입력 형식

The input consists of:</p>

  • one line with an integer n (1 ≤ n ≤ 10), where n is the number of ingredients used;
  • one line with n integers describing the order of the ingredients of the given cheeseburger. The ingredients are numbered from 1 to n.
## 출력 형식

Output the minimum number of bit-shuffles to correct the given cheeseburger.

예제 입력 1

9
3 4 7 8 9 1 2 5 6

예제 출력 1

1

예제 입력 2

3
1 3 2

예제 출력 2

1

Comments

There are no comments at the moment.