結果

問題 No.482 あなたの名は
ユーザー maspymaspy
提出日時 2020-01-27 20:55:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,596 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 27,156 KB
最終ジャッジ日時 2023-10-12 15:21:25
合計ジャッジ時間 11,663 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,320 KB
testcase_01 AC 16 ms
8,384 KB
testcase_02 AC 18 ms
8,372 KB
testcase_03 AC 17 ms
8,356 KB
testcase_04 AC 16 ms
8,260 KB
testcase_05 AC 16 ms
8,432 KB
testcase_06 AC 16 ms
8,248 KB
testcase_07 WA -
testcase_08 AC 16 ms
8,268 KB
testcase_09 AC 16 ms
8,356 KB
testcase_10 AC 17 ms
8,364 KB
testcase_11 AC 17 ms
8,280 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 16 ms
8,260 KB
testcase_15 AC 590 ms
27,004 KB
testcase_16 AC 581 ms
27,012 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 576 ms
26,980 KB
testcase_20 WA -
testcase_21 AC 585 ms
27,148 KB
testcase_22 AC 579 ms
26,940 KB
testcase_23 AC 572 ms
26,936 KB
testcase_24 WA -
testcase_25 AC 582 ms
27,092 KB
testcase_26 AC 578 ms
27,012 KB
testcase_27 AC 573 ms
26,968 KB
testcase_28 AC 572 ms
27,092 KB
testcase_29 AC 517 ms
26,964 KB
testcase_30 AC 17 ms
8,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)
        
    def build(self,seq):
        data = seq
        size = self.size
        for i,x in enumerate(data):
            j = i+(i&(-i))
            if j < size:
                data[j] += data[i]
        self.data = data
        
    def __repr__(self):
        return self.data.__repr__()
        
    def get_sum(self,i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        data = self.data
        size = self.size
        while i < size:
            data[i] += x
            i += i & -i
    
    def find_kth_element(self,k):
        data = self.data; size = self.size
        x,sx = 0,0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x,sx = y,sy
        return x + 1

def Inversion(seq):
    # seqは、1,2,...,Nの順列
    N = len(seq)
    bit = BinaryIndexedTree([0] * (N+1))
    inv = N*(N-1)//2
    for x in seq:
        inv -= bit.get_sum(x)
        bit.add(x,1)
    return inv

N,K,*D = map(int,read().split())

x = Inversion(D)

answer = 'YES' if K >= x and (K-x) % 2 == 0 else 'NO'
print(answer)
0