結果
問題 |
No.2382 Amidakuji M
|
ユーザー |
![]() |
提出日時 | 2023-07-14 21:58:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 758 ms / 2,000 ms |
コード長 | 467 bytes |
コンパイル時間 | 112 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 29,456 KB |
最終ジャッジ日時 | 2024-09-16 06:57:33 |
合計ジャッジ時間 | 6,767 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
class BIT: def __init__(self,n): self.n = n; self.k = [0]*(n+1) def a(self,i,x): while i<=self.n: self.k[i] += x; i += i&-i def s(self,i): t = 0 while i>0: t += self.k[i]; i -= i&-i return t n,m = map(int,input().split()) p = list(map(int,input().split())) bit = BIT(n); x = 0 for i,v in enumerate(p): x += i-bit.s(v); bit.a(v,1) if m%2==0 and m%2!=x%2: print(-1) else: y = -(-x//m)*m; print(y if y%2==x%2 else y+m)