結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー yvay5cqeyvay5cqe
提出日時 2021-08-18 00:40:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 222 ms / 2,500 ms
コード長 669 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-19 08:45:09
合計ジャッジ時間 1,711 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 35 ms
10,752 KB
testcase_08 AC 39 ms
10,624 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 222 ms
12,288 KB
testcase_12 AC 214 ms
12,416 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 29 ms
10,624 KB
testcase_15 AC 29 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def inversions(a):
    count = 0
    n = len(a)
    if n >= 2:
        b = a[0:n//2].copy()
        c = a[n//2:n].copy()
        count += inversions(b) + inversions(c)

        # b,c は sort されている。
        # merge sort をしていく流れで count
        ai = bi = ci = 0
        while ai < n:
            if bi < len(b) and (ci == len(c) or b[bi] <= c[ci]):
                a[ai] = b[bi]
                bi += 1
            else:
                count += len(b) - bi
                a[ai] = c[ci]
                ci += 1
            ai += 1
    return count


n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

print(inversions(a))
0