結果
| 問題 | No.3775 Distant Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-27 14:03:25 |
| 言語 | Python3 (3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 99 ms / 2,000 ms |
| + 898µs | |
| コード長 | 1,450 bytes |
| 記録 | |
| コンパイル時間 | 52 ms |
| コンパイル使用メモリ | 14,848 KB |
| 実行使用メモリ | 22,656 KB |
| 最終ジャッジ日時 | 2026-10-23 20:51:35 |
| 合計ジャッジ時間 | 3,494 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
import sys
import math
#from collections import deque, defaultdict, Counter
#import heapq
#import bisect
#import itertools
#import functools
# 外部ライブラリ(AtCoder環境で利用可能)
#from sortedcontainers import SortedList, SortedSet, SortedDict
#from atcoder.dsu import DSU
#from atcoder.segtree import SegTree
#from atcoder.lazysegtree import LazySegTree
#from atcoder.fenwicktree import FenwickTree
# 入力高速化
#input = sys.stdin.readline
# 再帰回数上限
sys.setrecursionlimit(10**9)
# よくあるmod
#MOD = 1000000007
MOD = 998244353
def bubble_sort(L):
action = []
goal = list(sorted(L))
for i, n in enumerate(goal):
cur = L.index(n)
while i != cur:
action.append((cur-1, cur))
L[cur-1], L[cur] = L[cur], L[cur-1]
cur -= 1
return action
def solve():
# 解答ここから
import heapq
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
sp = [[] for _ in range(K)]
for i in range(N):
if A[i] % K != (i+1) % K:
print(-1)
return
sp[(i+1) % K].append(A[i])
answer = []
for k in range(1, K+1):
actions = bubble_sort(sp[k % K])
for i, j in actions:
answer.append((K*i+k, K*j+k))
print(len(answer))
for i, j in answer:
print(i, j)
if __name__ == '__main__':
T = 1
for _ in range(T):
solve()