complete 33027.py 31159.rs

This commit is contained in:
2025-05-19 09:20:19 +09:00
parent bac11c76e0
commit b6fd714726
3 changed files with 69 additions and 74 deletions

View File

@@ -0,0 +1,28 @@
class AdrenalineRushSolver:
def __init__(self, n: int, final_order: list[int]):
self.n = n
self.final_order = final_order
def solve(self) -> list[tuple[int, int]]:
overtaken_history = []
for i in range(self.n):
ro = self.final_order.index(i)
for j in range(ro + 1, self.n):
overtaken_history.append((self.final_order[j], i))
for j in range(self.n - 1, ro, -1):
overtaken_history.append((i, self.final_order[j]))
for j in range(ro, i, -1):
overtaken_history.append((i, self.final_order[j - 1]))
self.final_order[j], self.final_order[j - 1] = self.final_order[j - 1], self.final_order[j]
return overtaken_history[::-1]
if __name__ == '__main__':
n = int(input())
final_order = list(map(lambda x: int(x) - 1, input().split()))
solved = AdrenalineRushSolver(n, final_order).solve()
print(len(solved))
for b, a in solved:
print(a + 1, b + 1)