| Task: | Pair sort |
| Sender: | hy2025_003 |
| Submission time: | 2025-09-24 17:55:42 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.04 s | details |
| #2 | WRONG ANSWER | 0.04 s | details |
| #3 | WRONG ANSWER | 0.04 s | details |
| #4 | WRONG ANSWER | 0.04 s | details |
| #5 | WRONG ANSWER | 0.04 s | details |
| #6 | WRONG ANSWER | 0.04 s | details |
| #7 | WRONG ANSWER | 0.04 s | details |
| #8 | WRONG ANSWER | 0.04 s | details |
| #9 | WRONG ANSWER | 0.05 s | details |
| #10 | WRONG ANSWER | 0.05 s | details |
| #11 | WRONG ANSWER | 0.06 s | details |
| #12 | WRONG ANSWER | 0.06 s | details |
| #13 | WRONG ANSWER | 0.09 s | details |
| #14 | WRONG ANSWER | 0.09 s | details |
Code
# def pair_sort(m):
# n = len(m)
# positions = {}
# for idx, val in enumerate(m):
# if val not in positions:
# positions[val] = []
# positions[val].append(idx)
# swap_count = 0
# i = 0
# swaps = []
# used = [False] * n
# while i < n - 1:
# if used[i]:
# i += 1
# continue
# if m[i] == m[i + 1] and not used[i + 1]:
# used[i] = used[i + 1] = True
# i += 2
# continue
# target = m[i]
# for pos in positions[target]:
# if pos > i + 1 and not used[pos]:
# m[i + 1], m[pos] = m[pos], m[i + 1]
# swaps.append((i + 1, pos))
# swap_count += 1
# used[i] = used[i + 1] = True
# break
# i += 2
# return swap_count, swaps
# n = int(input())
# m = list(map(int,input().split()))
# count, swaps = pair_sort(m)
# print(count)
# for swap in swaps:
# print(f"{swap[0]+1} {swap[1]+1}")
# print(*m)
def pair_sort(m):
n = len(m)
swap_count = 0
i = 0
swaps = []
while i < n - 2:
x = m[i]
if x == m[i+1]:
i+=2
break
j = i + 2
while j < n:
if (m[j] == x):
m[i + 1], m[j] = m[j], m[i + 1]
swaps.append((x,j))
swap_count += 1
i += 2
break
j += 1
return swap_count, swaps
n = int(input())
m = list(map(int,input().split()))
count, swaps = pair_sort(m)
print(count)
for swap in swaps:
print(f'{swap[0]} {swap[1]}')
# print(*m)
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 5 3 2 4 5 1 3 2 1 4 5 |
| correct output |
|---|
| 3 2 6 4 9 6 8 |
| user output |
|---|
| 3 3 5 4 8 1 7 |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 5 3 2 4 5 1 3 2 1 4 5 |
| correct output |
|---|
| 3 2 6 4 9 6 8 |
| user output |
|---|
| 3 3 5 4 8 1 7 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 3 6 6 8 8 9 9 1 4 5 2 4 10 2 1... |
| correct output |
|---|
| 9 2 17 4 17 6 17 8 17 ... |
| user output |
|---|
| 9 3 16 6 16 8 16 9 16 ... |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 10 3 6 6 8 8 9 9 1 4 5 2 4 10 2 1... |
| correct output |
|---|
| 9 2 17 4 17 6 17 8 17 ... |
| user output |
|---|
| 9 3 16 6 16 8 16 9 16 ... |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 50 47 26 6 35 13 18 9 19 14 50 34... |
| correct output |
|---|
| 48 2 87 4 78 6 71 8 55 ... |
| user output |
|---|
| 48 47 86 6 77 13 70 9 54 ... Truncated |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 50 47 26 6 35 13 18 9 19 14 50 34... |
| correct output |
|---|
| 48 2 87 4 78 6 71 8 55 ... |
| user output |
|---|
| 48 47 86 6 77 13 70 9 54 ... Truncated |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 100 56 26 6 35 60 72 9 55 83 51 58... |
| correct output |
|---|
| 97 2 77 4 108 6 141 8 55 ... |
| user output |
|---|
| 60 56 76 6 107 60 140 9 54 ... Truncated |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 100 56 26 6 35 60 72 9 55 83 51 58... |
| correct output |
|---|
| 97 2 77 4 108 6 141 8 55 ... |
| user output |
|---|
| 60 56 76 6 107 60 140 9 54 ... Truncated |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 500 56 146 351 35 281 235 354 449 ... |
| correct output |
|---|
| 497 2 758 4 820 6 125 8 243 ... |
| user output |
|---|
| 269 56 757 351 819 281 124 354 242 ... Truncated |
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 500 56 146 351 35 281 235 354 449 ... |
| correct output |
|---|
| 497 2 758 4 820 6 125 8 243 ... |
| user output |
|---|
| 269 56 757 351 819 281 124 354 242 ... Truncated |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 1000 603 596 351 885 530 235 354 56... |
| correct output |
|---|
| 993 2 256 4 1534 6 816 8 1057 ... |
| user output |
|---|
| 913 603 255 351 1533 530 815 354 1056 ... Truncated |
Test 12
Verdict: WRONG ANSWER
| input |
|---|
| 1000 603 596 351 885 530 235 354 56... |
| correct output |
|---|
| 993 2 256 4 1534 6 816 8 1057 ... |
| user output |
|---|
| 913 603 255 351 1533 530 815 354 1056 ... Truncated |
Test 13
Verdict: WRONG ANSWER
| input |
|---|
| 5000 1594 596 1797 3776 1201 235 35... |
| correct output |
|---|
| 4993 2 1548 4 9062 6 6397 8 8296 ... |
| user output |
|---|
| 2571 1594 1547 1797 9061 1201 6396 354 8295 ... Truncated |
Test 14
Verdict: WRONG ANSWER
| input |
|---|
| 5000 1594 596 1797 3776 1201 235 35... |
| correct output |
|---|
| 4993 2 1548 4 9062 6 6397 8 8296 ... |
| user output |
|---|
| 2571 1594 1547 1797 9061 1201 6396 354 8295 ... Truncated |
