結果

問題 No.2029 Swap Min Max Min
ユーザー mkawa2mkawa2
提出日時 2022-08-08 00:37:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 110,744 KB
最終ジャッジ日時 2023-10-17 18:59:51
合計ジャッジ時間 7,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,496 KB
testcase_01 AC 37 ms
53,496 KB
testcase_02 AC 37 ms
53,496 KB
testcase_03 AC 88 ms
93,940 KB
testcase_04 AC 61 ms
75,368 KB
testcase_05 AC 59 ms
78,052 KB
testcase_06 AC 76 ms
96,780 KB
testcase_07 AC 90 ms
97,036 KB
testcase_08 AC 105 ms
102,616 KB
testcase_09 AC 65 ms
80,420 KB
testcase_10 AC 53 ms
72,144 KB
testcase_11 AC 75 ms
87,412 KB
testcase_12 AC 63 ms
83,776 KB
testcase_13 AC 107 ms
101,968 KB
testcase_14 AC 91 ms
105,132 KB
testcase_15 AC 110 ms
104,276 KB
testcase_16 AC 92 ms
104,540 KB
testcase_17 AC 106 ms
101,936 KB
testcase_18 AC 111 ms
104,672 KB
testcase_19 AC 91 ms
104,300 KB
testcase_20 AC 92 ms
104,868 KB
testcase_21 AC 91 ms
104,308 KB
testcase_22 AC 91 ms
104,540 KB
testcase_23 AC 99 ms
110,744 KB
testcase_24 AC 97 ms
106,256 KB
testcase_25 AC 89 ms
110,744 KB
testcase_26 AC 86 ms
106,256 KB
testcase_27 AC 37 ms
53,496 KB
testcase_28 AC 37 ms
53,496 KB
testcase_29 AC 37 ms
53,496 KB
testcase_30 AC 37 ms
53,496 KB
testcase_31 AC 36 ms
53,496 KB
testcase_32 AC 42 ms
59,528 KB
testcase_33 AC 37 ms
53,496 KB
testcase_34 AC 37 ms
53,496 KB
testcase_35 AC 36 ms
53,496 KB
testcase_36 AC 36 ms
53,496 KB
testcase_37 AC 36 ms
53,496 KB
testcase_38 AC 94 ms
106,080 KB
testcase_39 AC 87 ms
109,580 KB
testcase_40 AC 83 ms
106,072 KB
testcase_41 AC 93 ms
103,848 KB
testcase_42 AC 93 ms
103,592 KB
testcase_43 AC 85 ms
106,332 KB
testcase_44 AC 100 ms
105,176 KB
権限があれば一括ダウンロードができます

ソースコード

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