結果
| 問題 | No.2382 Amidakuji M |
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2023-07-14 21:58:25 |
| 言語 | Python3 (3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 499 ms / 2,000 ms |
| + 959µs | |
| コード長 | 467 bytes |
| 記録 | |
| コンパイル時間 | 790 ms |
| コンパイル使用メモリ | 14,720 KB |
| 実行使用メモリ | 31,620 KB |
| 最終ジャッジ日時 | 2026-10-17 08:11:12 |
| 合計ジャッジ時間 | 6,348 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
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)
ニックネーム