結果

問題 No.366 ロボットソート
ユーザー むらためむらため
提出日時 2019-01-21 15:17:56
言語 Nim
(2.0.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 603 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 67,244 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 02:28:00
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,algorithm
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

let n = scan()
let k = scan()
var A = newSeqWith(n,scan())
let B = A.sorted(cmp)
var ans = 0
for i,b in B:
  if A[i] == b : continue
  # var p = toSeq(0..<n).filterIt(A[it] == b)[0]
  var p = 0
  for pi in (i+1)..<n:
    if A[pi] == b:
      p = pi
      break
  while A[i] != b:
    if p - k < 0 : quit "-1",0
    swap(A[p],A[p-k])
    p -= k
    ans += 1
echo ans
0