結果
問題 | No.2029 Swap Min Max Min |
ユーザー | とりゐ |
提出日時 | 2022-06-29 22:14:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,154 bytes |
コンパイル時間 | 406 ms |
コンパイル使用メモリ | 87,236 KB |
実行使用メモリ | 117,076 KB |
最終ジャッジ日時 | 2023-10-14 00:01:43 |
合計ジャッジ時間 | 9,358 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,316 KB |
testcase_01 | AC | 72 ms
71,364 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 118 ms
87,916 KB |
testcase_06 | AC | 151 ms
102,016 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 106 ms
82,192 KB |
testcase_11 | WA | - |
testcase_12 | AC | 127 ms
91,740 KB |
testcase_13 | WA | - |
testcase_14 | AC | 177 ms
111,864 KB |
testcase_15 | WA | - |
testcase_16 | AC | 178 ms
112,748 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 171 ms
111,896 KB |
testcase_20 | AC | 175 ms
111,848 KB |
testcase_21 | AC | 177 ms
111,852 KB |
testcase_22 | AC | 177 ms
112,804 KB |
testcase_23 | AC | 225 ms
116,880 KB |
testcase_24 | AC | 227 ms
116,976 KB |
testcase_25 | AC | 175 ms
112,784 KB |
testcase_26 | AC | 184 ms
112,704 KB |
testcase_27 | AC | 76 ms
71,496 KB |
testcase_28 | AC | 82 ms
75,720 KB |
testcase_29 | AC | 77 ms
71,368 KB |
testcase_30 | AC | 84 ms
75,680 KB |
testcase_31 | AC | 83 ms
75,780 KB |
testcase_32 | WA | - |
testcase_33 | AC | 79 ms
71,100 KB |
testcase_34 | AC | 75 ms
71,248 KB |
testcase_35 | AC | 74 ms
71,336 KB |
testcase_36 | AC | 74 ms
71,452 KB |
testcase_37 | AC | 76 ms
71,060 KB |
testcase_38 | AC | 222 ms
114,948 KB |
testcase_39 | AC | 181 ms
112,164 KB |
testcase_40 | AC | 172 ms
110,052 KB |
testcase_41 | AC | 210 ms
113,696 KB |
testcase_42 | AC | 213 ms
113,736 KB |
testcase_43 | AC | 172 ms
114,140 KB |
testcase_44 | AC | 231 ms
116,600 KB |
ソースコード
class Bit: def __init__(self,n): self.size=n self.tree=[0]*(n+1) def sum(self, i): s=0 while i>0: s+=self.tree[i] i-=i&-i return s def add(self,i,x): while i<=self.size: self.tree[i]+=x i+=i&-i def inversion(a,flag=True): n=len(a) if flag: b=[(a[i],i+1) for i in range(n)] b.sort(key=lambda x:x[0]) a=[i[1] for i in b] bit=Bit(n) cnt=0 for i in range(n): bit.add(a[i],1) cnt+=i+1-bit.sum(a[i]) return cnt n=int(input()) a=list(map(int,input().split())) x=n//2 if n%2==0: c1=[0]*n c2=[0]*n big1=list(range(1,n+1,2))[::-1] small1=list(range(2,n+1,2))[::-1] big2=list(range(2,n+1,2))[::-1] small2=list(range(1,n+1,2))[::-1] for i in range(n): if a[i]<=x: c1[i]=small1.pop() c2[i]=small2.pop() else: c1[i]=big1.pop() c2[i]=big2.pop() print(x,min(inversion(c1,flag=False),inversion(c2,flag=False))) else: c=[0]*n small=list(range(2,n+1,2))[::-1] big=list(range(1,n+1,2))[::-1] for i in range(n): if a[i]<=x: c[i]=small.pop() else: c[i]=big.pop() print(x,inversion(c,flag=False))