結果

問題 No.482 あなたの名は
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-02-10 23:17:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 98,412 KB
最終ジャッジ日時 2023-08-28 08:48:35
合計ジャッジ時間 7,968 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,312 KB
testcase_01 AC 69 ms
71,036 KB
testcase_02 AC 69 ms
71,140 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 79 ms
75,448 KB
testcase_09 AC 72 ms
71,116 KB
testcase_10 AC 80 ms
75,484 KB
testcase_11 AC 80 ms
75,364 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 81 ms
75,740 KB
testcase_15 AC 272 ms
98,332 KB
testcase_16 AC 265 ms
98,000 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 258 ms
98,016 KB
testcase_20 WA -
testcase_21 AC 263 ms
98,164 KB
testcase_22 AC 262 ms
98,412 KB
testcase_23 AC 258 ms
98,012 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 263 ms
98,024 KB
testcase_28 AC 272 ms
98,152 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import sys


REC_LIMIT = 10000


# http://www.prefield.com/algorithm/sort/mergecount.html
def inversion_number(xs):
    n = len(xs)
    cnt = 0
    if n > 1:
        bs = xs[:n // 2]
        cs = xs[n // 2:]
        cnt += inversion_number(bs)
        cnt += inversion_number(cs)
        j = 0
        k = 0
        for i in range(n):
            if k == len(cs):
                xs[i] = bs[j]
                j += 1
            elif j == len(bs):
                xs[i] = cs[k]
                k += 1
            elif bs[j] <= cs[k]:
                xs[i] = bs[j]
                j += 1
            else:
                xs[i] = cs[k]
                k += 1
                cnt += n // 2 - j
    return cnt


def judge(n, k, ds):
    inv_n = inversion_number(ds)
    return (inv_n // 2) % k == 0


def main():
    sys.setrecursionlimit(REC_LIMIT)
    n, k = (int(x) for x in input().split())
    ds = [int(x) for x in input().split()]
    print("YES" if judge(n, k, ds) else "NO")


if __name__ == '__main__':
    main()
0