시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 49 13 13 31.707%

문제

상근이는 박스 N개를 로봇을 이용해서 정렬하려고 한다. 박스에는 1부터 N까지 숫자가 겹치지 않게 쓰여 있고, 이 수가 오름차순을 이루도록 박스를 정렬하려고 한다.

상근이가 가지고 있는 로봇에 수열을 입력하면, 위치에 해당하는 박스를 교환하게 된다. 수열에는 같은 위치가 두 번 이상 주어지면 안 된다.

예를 들어, 박스가 지금 [4, 1, 5, 2, 3] 순서로 놓여져 있고, 로봇에 [2, 1, 3] 명령을 내렸다고 해보자. 그럼 두 번째 위치에 있는 박스를 위치 1로 옮기고, 첫 번째 박스는 위치 3으로, 세 번째 박스는 위치 2로 이동하게 된다. 박스의 순서는 [1, 5, 4, 2, 3]이 된다.

명령을 가장 적게 이용해서 박스를 정렬하는 프로그램을 작성하시오.

입력

첫째 줄에 박스의 수 N이 주어진다. (2 ≤ N ≤ 1000)

다음 줄에는 박스에 붙어있는 숫자가 순서대로 주어진다. 같은 숫자가 두 번 이상 주어지지 않는다.

출력

첫째 줄에 정렬하는데 사용한 명령의 수 X를 출력한다.

그 다음 X개 줄에는 로봇에게 내린 명령을 순서대로 출력한다. 가장 첫 숫자는 수열의 길이이며, 그 다음에 콜론(:)과 공백을 출력하고, 수열의 각 원소를 출력한다.

예제 입력 1

3
3 2 1

예제 출력 1

1
2: 3 1
W3sicHJvYmxlbV9pZCI6IjI4MzQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJjMTVcdWMyYTQgXHVjODE1XHViODJjIiwiZGVzY3JpcHRpb24iOiI8cD5cdWMwYzFcdWFkZmNcdWM3NzRcdWIyOTQgXHViYzE1XHVjMmE0IE5cdWFjMWNcdWI5N2MgXHViODVjXHViZDA3XHVjNzQ0IFx1Yzc3NFx1YzZhOVx1ZDU3NFx1YzExYyBcdWM4MTVcdWI4MmNcdWQ1NThcdWI4MjRcdWFjZTAgXHVkNTVjXHViMmU0LiBcdW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yIFgsIG1pbmltdW0gbnVtYmVyIG9mIG9wZXJhdGlvbnMgcmVxdWlyZWQuJm5ic3A7PFwvcD5cclxuXHJcbjxwPlRoZSBmb2xsb3dpbmcgWCBsaW5lcyBzaG91bGQgY29udGFpbiB0aGUgc2VxdWVuY2VzIGdpdmVuIHRvIHJvYm90LCBvbmUgc2VxdWVuY2UgcGVyIGxpbmUuJm5ic3A7PFwvcD5cclxuXHJcbjxwPkVhY2ggbGluZSBzaG91bGQgc3RhcnQgd2l0aCB0aGUgbGVuZ3RoIG9mIHRoZSBzZXF1ZW5jZSwgZm9sbG93ZWQgYnkgYSBjb2xvbiwgYSBzaW5nbGUgd2hpdGUgc3BhY2UsIGFuZCB0aGVuIHNwYWNlIHNlcGVyYXRlZCBzZXF1ZW5jZSBvZiBwb3NpdGlvbnMuJm5ic3A7PFwvcD5cclxuXHJcbjxwPk5PVEU6IFRoZXJlIG1heSBiZSBtdWx0aXBsZSBzb2x1dGlvbnMgYW5kIHlvdSBjYW4gb3V0cHV0IGFueSBvZiB0aGUuPFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2011 > Croatian Olympiad in Informatics 2011 1번

  • 문제를 번역한 사람: baekjoon
  • 문제의 오타를 찾은 사람: jh05013