結果

問題 No.2382 Amidakuji M
ユーザー yabityabit
提出日時 2023-07-14 22:02:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,164 bytes
コンパイル時間 1,177 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 108,972 KB
最終ジャッジ日時 2023-10-14 12:13:37
合計ジャッジ時間 5,208 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,112 KB
testcase_01 AC 71 ms
71,180 KB
testcase_02 AC 71 ms
71,100 KB
testcase_03 AC 152 ms
90,744 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 136 ms
92,556 KB
testcase_07 AC 116 ms
85,672 KB
testcase_08 AC 86 ms
76,404 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 178 ms
100,224 KB
testcase_13 AC 73 ms
71,112 KB
testcase_14 AC 73 ms
71,084 KB
testcase_15 AC 73 ms
71,152 KB
testcase_16 AC 73 ms
71,220 KB
testcase_17 AC 72 ms
71,244 KB
testcase_18 WA -
testcase_19 AC 213 ms
108,860 KB
testcase_20 AC 211 ms
108,636 KB
testcase_21 AC 220 ms
108,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        # 配列0番目からiまでの総和を出力
        # i: 1-indexed
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        # i番目にxを可算
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def update(self, i, x):
        # i番目を加算処理でxに更新する
        self.add(i, -self.sum(i) + self.sum(i - 1))
        self.add(i, x)

    def debug(self):
        # 現在の配列状況を出力する
        res = []
        for i in range(self.size):
            res.append(self.sum(i + 1) - self.sum(i))
        return res


def inversion_number(A):
    b = BIT(N)
    invert = 0
    for i in range(N):
        invert += b.sum(N) - b.sum(A[i])
        b.add(A[i], 1)
    return invert


N, M = map(int, input().split())
P = list(map(int, input().split()))
inv = inversion_number(P)
moyori = M * -(-inv // M)
# print(inv, moyori)
if (moyori - inv) % 2 == 0:
    print(moyori)
else:
    print(-1)
0