結果

問題 No.366 ロボットソート
ユーザー HachimoriHachimori
提出日時 2016-04-29 22:54:28
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 760 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-15 05:45:12
合計ジャッジ時間 1,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8


def read():
    N, K = map(int, raw_input().split())
    vList = map(int, raw_input().split())
    return K, vList


def calcCost(subList):
    ret = 0
    for i in range(len(subList)):
        for j in range(len(subList) - i - 1):
            if subList[j] > subList[j + 1]:
                subList[j], subList[j + 1] = subList[j + 1], subList[j]
                ret += 1
    return ret


def work((K, vList)):
    
    for i in range(K - 1):
        if i + K >= len(vList) and i + 1 < len(vList) and vList[i] > vList[i + 1]:
            print -1
            return

    ans = 0
    for i in range(min(K, len(vList) - K)):
        ans += calcCost(vList[i::K])

    print ans


if __name__ == "__main__":
    work(read())

0