結果
問題 | No.2029 Swap Min Max Min |
ユーザー | 已经死了 |
提出日時 | 2024-06-27 21:07:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,789 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 82,264 KB |
実行使用メモリ | 279,144 KB |
最終ジャッジ日時 | 2024-06-27 21:07:45 |
合計ジャッジ時間 | 24,498 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 156 ms
92,160 KB |
testcase_01 | AC | 155 ms
92,160 KB |
testcase_02 | AC | 155 ms
91,904 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 265 ms
123,456 KB |
testcase_06 | AC | 365 ms
164,904 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 226 ms
106,372 KB |
testcase_11 | WA | - |
testcase_12 | AC | 291 ms
134,940 KB |
testcase_13 | WA | - |
testcase_14 | AC | 467 ms
173,900 KB |
testcase_15 | WA | - |
testcase_16 | AC | 445 ms
173,180 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 454 ms
173,624 KB |
testcase_20 | AC | 465 ms
173,860 KB |
testcase_21 | AC | 471 ms
173,672 KB |
testcase_22 | AC | 447 ms
172,928 KB |
testcase_23 | AC | 910 ms
273,648 KB |
testcase_24 | AC | 930 ms
273,240 KB |
testcase_25 | AC | 414 ms
174,156 KB |
testcase_26 | AC | 413 ms
174,164 KB |
testcase_27 | AC | 159 ms
92,160 KB |
testcase_28 | AC | 163 ms
92,672 KB |
testcase_29 | AC | 160 ms
92,672 KB |
testcase_30 | AC | 160 ms
92,672 KB |
testcase_31 | AC | 162 ms
92,672 KB |
testcase_32 | WA | - |
testcase_33 | AC | 157 ms
92,160 KB |
testcase_34 | AC | 159 ms
91,904 KB |
testcase_35 | AC | 158 ms
92,288 KB |
testcase_36 | AC | 155 ms
92,160 KB |
testcase_37 | AC | 156 ms
92,416 KB |
testcase_38 | AC | 899 ms
274,504 KB |
testcase_39 | AC | 440 ms
172,992 KB |
testcase_40 | AC | 419 ms
171,708 KB |
testcase_41 | AC | 939 ms
277,276 KB |
testcase_42 | AC | 946 ms
279,144 KB |
testcase_43 | AC | 433 ms
172,488 KB |
testcase_44 | AC | 1,016 ms
276,112 KB |
ソースコード
import os,sys,random,threading #sys.exit() 退出程序 from random import randint,choice,shuffle #randint(a,b)从[a,b]范围随机选择一个数 #choice(seq)seq可以是一个列表,元组或字符串,从seq中随机选取一个元素 #shuffle(x)将一个可变的序列x中的元素打乱 from copy import deepcopy from io import BytesIO,IOBase from types import GeneratorType from functools import lru_cache,reduce #reduce(op,迭代对象) from bisect import bisect_left,bisect_right #bisect_left(x) 大于等于x的第一个下标 #bisect_right(x) 大于x的第一个下标 from collections import Counter,defaultdict,deque from itertools import accumulate,combinations,permutations #accumulate(a)用a序列生成一个累积迭代器,一般list化前面放个[0]做前缀和用 #combinations(a,k)a序列选k个 组合迭代器 #permutations(a,k)a序列选k个 排列迭代器 from heapq import heapify,heappop,heappush #heapify将列表转为堆 from typing import Generic,Iterable,Iterator,TypeVar,Union,List from string import ascii_lowercase,ascii_uppercase,digits #小写字母,大写字母,十进制数字 from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf #ceil向上取整,floor向下取整 ,sqrt开方 ,factorial阶乘 from decimal import Decimal,getcontext #Decimal(s) 实例化Decimal对象,一般使用字符串 #getcontext().prec=100 修改精度 from sys import stdin, stdout, setrecursionlimit input = lambda: sys.stdin.readline().rstrip("\r\n") MI = lambda :map(int,input().split()) li = lambda :list(MI()) ii = lambda :int(input()) mod = int(1e9 + 7) #998244353 inf = int(1e20) py = lambda :print("YES") pn = lambda :print("NO") DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上 DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗ import os,sys,random,threading #sys.exit() 退出程序 #sys.setrecursionlimit(10**6) #调整栈空间 from random import randint,choice,shuffle #randint(a,b)从[a,b]范围随机选择一个数 #choice(seq)seq可以是一个列表,元组或字符串,从seq中随机选取一个元素 #shuffle(x)将一个可变的序列x中的元素打乱 from copy import deepcopy from io import BytesIO,IOBase from types import GeneratorType from functools import lru_cache,reduce #reduce(op,迭代对象) from bisect import bisect_left,bisect_right #bisect_left(x) 大于等于x的第一个下标 #bisect_right(x) 大于x的第一个下标 from collections import Counter,defaultdict,deque from itertools import accumulate,combinations,permutations #accumulate(a)用a序列生成一个累积迭代器,一般list化前面放个[0]做前缀和用 #combinations(a,k)a序列选k个 组合迭代器 #permutations(a,k)a序列选k个 排列迭代器 from heapq import heapify,heappop,heappush #heapify将列表转为堆 from typing import Generic,Iterable,Iterator,TypeVar,Union,List from string import ascii_lowercase,ascii_uppercase,digits #小写字母,大写字母,十进制数字 from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf #ceil向上取整,floor向下取整 ,sqrt开方 ,factorial阶乘 from decimal import Decimal,getcontext #Decimal(s) 实例化Decimal对象,一般使用字符串 #getcontext().prec=100 修改精度 from sys import stdin, stdout, setrecursionlimit input = lambda: sys.stdin.readline().rstrip("\r\n") MI = lambda :map(int,input().split()) li = lambda :list(MI()) ii = lambda :int(input()) mod = int(1e9 + 7) #998244353 inf = 1<<60 py = lambda :print("YES") pn = lambda :print("NO") DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上 DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗ class BIT1: """单点修改,区间和查询""" __slots__ = "size", "bit", "tree" def __init__(self, n: int): self.size = n self.bit = n.bit_length() self.tree = [0]*(n+1) def add(self, index: int, delta: int) -> None: # index 必须大于0 while index <= self.size: self.tree[index]+=delta index += index & -index def _query(self, index: int) -> int: res = 0 while index > 0: res += self.tree[index] index -= index & -index return res def query(self, left: int, right: int) -> int: return self._query(right) - self._query(left - 1) def cal(arr,brr): idx=defaultdict(list) for i,b in enumerate(brr,2): idx[b].append(i) cnt=defaultdict(int) al=[] for a in arr: al.append(idx[a][cnt[a]]) cnt[a]+=1 bit=BIT1(n+10) res=0 for i in al: res+=bit.query(i+1,n+5) bit.add(i,1) return res n=ii() a=li() mid=n//2 if n%2==1: x=[] y=[] for i in a: if i<=mid: x.append(i) else: y.append(i) x=x[::-1] y=y[::-1] b=[0]*n for i in range(n): if i%2==0: b[i]=y.pop() else: b[i]=x.pop() print(mid,cal(a,b)) else: ans=inf x=[] y=[] for i in a: if i<=mid: x.append(i) else: y.append(i) x=x[::-1] y=y[::-1] b=[0]*n for i in range(n): if i%2==0: b[i]=y.pop() else: b[i]=x.pop() ans=min(ans,cal(a,b)) b[-1],b[-2]=b[-2],b[-1] ans=min(ans,cal(a,b)) x=[] y=[] for i in a: if i<=mid: x.append(i) else: y.append(i) x=x[::-1] y=y[::-1] b=[0]*n for i in range(n): if i%2==0: b[i]=x.pop() else: b[i]=y.pop() ans=min(ans,cal(a,b)) b[0],b[1]=b[1],b[0] ans=min(ans,cal(a,b)) print(mid,ans)