結果

問題 No.2382 Amidakuji M
ユーザー miho-4miho-4
提出日時 2023-07-14 22:38:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 108,760 KB
最終ジャッジ日時 2023-10-14 12:54:14
合計ジャッジ時間 4,789 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,128 KB
testcase_01 AC 75 ms
71,228 KB
testcase_02 AC 75 ms
71,272 KB
testcase_03 AC 168 ms
89,224 KB
testcase_04 AC 165 ms
101,456 KB
testcase_05 AC 96 ms
78,196 KB
testcase_06 AC 127 ms
90,924 KB
testcase_07 AC 114 ms
84,488 KB
testcase_08 AC 85 ms
76,256 KB
testcase_09 AC 156 ms
95,576 KB
testcase_10 AC 182 ms
104,984 KB
testcase_11 AC 115 ms
86,224 KB
testcase_12 AC 147 ms
97,872 KB
testcase_13 AC 75 ms
71,272 KB
testcase_14 AC 74 ms
71,308 KB
testcase_15 AC 76 ms
71,252 KB
testcase_16 AC 75 ms
71,116 KB
testcase_17 AC 77 ms
70,920 KB
testcase_18 AC 76 ms
70,924 KB
testcase_19 AC 199 ms
108,568 KB
testcase_20 AC 195 ms
108,604 KB
testcase_21 AC 192 ms
108,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
L=list(map(int,input().split()))


data = [0]*(n+1)
def add(i, x):
    while i <= n:
        data[i] += x
        i += i & -i
def get(i):
    s = 0
    while i:
        s += data[i]
        i -= i & -i
    return s

ans = 0
for a in L:
    add(a, 1)
    ans += a-get(a)

#ans+2x==km
if ans%2==1 and m%2==0:
  exit(print(-1))
k=0
if m<ans:
  k=ans//m
for i in range(k,k+10):
  if ans<=i*m and ans%2==i*m%2:
    exit(print(i*m))
0