結果

問題 No.2029 Swap Min Max Min
ユーザー EguyEguy
提出日時 2022-08-05 22:44:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 113,224 KB
最終ジャッジ日時 2023-10-14 00:17:04
合計ジャッジ時間 7,167 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,224 KB
testcase_01 AC 72 ms
71,304 KB
testcase_02 AC 71 ms
71,000 KB
testcase_03 AC 122 ms
99,520 KB
testcase_04 AC 102 ms
81,440 KB
testcase_05 AC 94 ms
88,192 KB
testcase_06 AC 114 ms
105,284 KB
testcase_07 AC 129 ms
102,032 KB
testcase_08 AC 143 ms
108,728 KB
testcase_09 AC 110 ms
86,360 KB
testcase_10 AC 89 ms
80,976 KB
testcase_11 AC 113 ms
91,248 KB
testcase_12 AC 99 ms
92,444 KB
testcase_13 AC 146 ms
109,036 KB
testcase_14 AC 127 ms
107,216 KB
testcase_15 AC 147 ms
107,156 KB
testcase_16 AC 130 ms
107,188 KB
testcase_17 AC 144 ms
108,920 KB
testcase_18 AC 146 ms
107,456 KB
testcase_19 AC 128 ms
107,272 KB
testcase_20 AC 128 ms
107,032 KB
testcase_21 AC 130 ms
107,240 KB
testcase_22 AC 127 ms
107,084 KB
testcase_23 AC 131 ms
107,432 KB
testcase_24 AC 130 ms
107,444 KB
testcase_25 AC 123 ms
107,280 KB
testcase_26 AC 125 ms
107,296 KB
testcase_27 AC 73 ms
71,024 KB
testcase_28 AC 74 ms
71,292 KB
testcase_29 AC 73 ms
71,260 KB
testcase_30 AC 74 ms
71,388 KB
testcase_31 AC 73 ms
70,940 KB
testcase_32 AC 75 ms
71,088 KB
testcase_33 AC 72 ms
71,152 KB
testcase_34 AC 73 ms
71,224 KB
testcase_35 AC 71 ms
71,176 KB
testcase_36 AC 73 ms
71,308 KB
testcase_37 AC 73 ms
71,228 KB
testcase_38 AC 129 ms
108,916 KB
testcase_39 AC 124 ms
107,272 KB
testcase_40 AC 128 ms
108,900 KB
testcase_41 AC 131 ms
109,128 KB
testcase_42 AC 130 ms
109,176 KB
testcase_43 AC 124 ms
113,224 KB
testcase_44 AC 131 ms
107,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(1000000)
INF = 1 << 100
#mod = 1000000007
mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
li = lambda: list(map(int, input().split()))

N = int(input())
A = li()

idx = []
for i in range(N):
    if A[i] <= N // 2:
        idx.append(i)

lst = []
for i in range(N % 2, N, 2):
    lst.append(i)

Y = 0
for a, b in zip(idx, lst):
    Y += abs(a - b)

if N % 2:
    print(N // 2, Y)
    exit()

dp = [[INF] * 2 for _ in range(N//2)]
dp[0][0] = idx[0]
dp[0][1] = abs(idx[0] - 1)

for i in range(1, N//2):
    x = i * 2
    dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + abs(idx[i] - x)
    dp[i][1] = dp[i-1][1] + abs(idx[i] - (x + 1))

print(N//2, min(dp[-1]))
0