結果

問題 No.2029 Swap Min Max Min
ユーザー mkawa2
提出日時 2022-08-08 00:37:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 110,692 KB
最終ジャッジ日時 2024-09-17 16:12:44
合計ジャッジ時間 5,643 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

def cost(aa):
    s = t = 0
    cs = [0]
    for a in aa:
        if a <= n//2:
            s += 1
            cs.append(abs(s-t)+cs[-1])
        else:
            t += 1
    return cs

n = II()
aa = LI()

ll = cost(aa)
if n & 1:
    y = ll[-1]
else:
    rr = cost(aa[::-1])[::-1]
    y = min(l+r for l, r in zip(ll, rr))

print(n//2, y)
0