結果

問題 No.2382 Amidakuji M
ユーザー かつっぱ競プロかつっぱ競プロ
提出日時 2023-07-14 21:44:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 713 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 10,772 KB
実行使用メモリ 31,692 KB
最終ジャッジ日時 2023-10-14 11:49:28
合計ジャッジ時間 6,840 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
9,692 KB
testcase_01 AC 19 ms
9,632 KB
testcase_02 AC 19 ms
9,684 KB
testcase_03 AC 297 ms
19,088 KB
testcase_04 AC 511 ms
27,196 KB
testcase_05 AC 94 ms
12,308 KB
testcase_06 AC 336 ms
20,712 KB
testcase_07 AC 214 ms
16,436 KB
testcase_08 AC 34 ms
10,296 KB
testcase_09 AC 453 ms
24,668 KB
testcase_10 AC 673 ms
30,932 KB
testcase_11 AC 238 ms
17,364 KB
testcase_12 AC 442 ms
24,920 KB
testcase_13 AC 19 ms
9,616 KB
testcase_14 AC 19 ms
9,628 KB
testcase_15 AC 20 ms
9,752 KB
testcase_16 AC 20 ms
9,620 KB
testcase_17 AC 19 ms
9,608 KB
testcase_18 AC 19 ms
9,628 KB
testcase_19 AC 709 ms
31,692 KB
testcase_20 AC 706 ms
31,604 KB
testcase_21 AC 713 ms
31,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

bit = [0] * 220000


def add(x):
    x += 1
    while x < len(bit):
        bit[x] += 1
        x += x & -x


def getSum(x):
    x += 1
    ans = 0
    while x > 0:
        ans += bit[x]
        x -= x & -x

    return ans


N, M = map(int, input().split())
P = list(map(int, input().split()))

r = 0

for p in P[::-1]:
    r += getSum(p)
    add(p)


ans = r // M * M

for _ in range(6):
    if ans >= r and ans % 2 == r % 2:
        print(ans)
        exit()
    ans += M

print(-1)
0