結果

問題 No.2029 Swap Min Max Min
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-08-05 23:19:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 112,780 KB
最終ジャッジ日時 2023-10-14 01:09:48
合計ジャッジ時間 7,807 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,068 KB
testcase_01 AC 72 ms
70,788 KB
testcase_02 AC 72 ms
70,944 KB
testcase_03 AC 130 ms
98,592 KB
testcase_04 AC 106 ms
82,572 KB
testcase_05 AC 91 ms
86,536 KB
testcase_06 AC 108 ms
100,792 KB
testcase_07 AC 133 ms
100,040 KB
testcase_08 AC 165 ms
108,656 KB
testcase_09 AC 112 ms
88,028 KB
testcase_10 AC 85 ms
80,472 KB
testcase_11 AC 118 ms
91,492 KB
testcase_12 AC 95 ms
90,304 KB
testcase_13 AC 162 ms
108,808 KB
testcase_14 AC 122 ms
107,152 KB
testcase_15 AC 174 ms
106,916 KB
testcase_16 AC 124 ms
106,956 KB
testcase_17 AC 164 ms
108,948 KB
testcase_18 AC 169 ms
107,228 KB
testcase_19 AC 121 ms
106,844 KB
testcase_20 AC 120 ms
107,324 KB
testcase_21 AC 124 ms
106,840 KB
testcase_22 AC 124 ms
107,040 KB
testcase_23 AC 166 ms
107,012 KB
testcase_24 AC 165 ms
107,148 KB
testcase_25 AC 117 ms
107,392 KB
testcase_26 AC 117 ms
107,244 KB
testcase_27 AC 71 ms
71,060 KB
testcase_28 AC 73 ms
70,968 KB
testcase_29 AC 70 ms
71,164 KB
testcase_30 AC 72 ms
70,928 KB
testcase_31 AC 71 ms
71,180 KB
testcase_32 AC 79 ms
75,952 KB
testcase_33 AC 70 ms
70,776 KB
testcase_34 AC 68 ms
71,044 KB
testcase_35 AC 69 ms
71,024 KB
testcase_36 AC 68 ms
71,080 KB
testcase_37 AC 70 ms
71,296 KB
testcase_38 AC 152 ms
110,148 KB
testcase_39 AC 120 ms
107,088 KB
testcase_40 AC 109 ms
108,320 KB
testcase_41 AC 156 ms
108,896 KB
testcase_42 AC 154 ms
108,904 KB
testcase_43 AC 122 ms
112,780 KB
testcase_44 AC 166 ms
107,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int,input().split()))

ans = n//2
l = []
for i,a in enumerate(A):
    if a <= ans:
        l.append(i)


score = 0
for i in range(len(l)):
    t = 2*i+n%2
    score += abs(t-l[i])

if n%2:
    print(ans,score)
    exit()

inf = 10**10
dp = [[inf]*2 for i in range(n)]
dp[1][0] = abs(1-l[0])

for i in range(1,n):
    for j in range(2):
        if dp[i][j] == inf:
            continue
        nid = (i+1)//2+j

        if nid >= ans:
            continue
        s = dp[i][j]
        if j == 0:
            if i+2 < n:
                dp[i+2][0] = min(dp[i+2][0],abs(i+2-l[nid])+s)
            if i+1 < n:
                dp[i+1][1] = min(dp[i+1][1],abs(i+1-l[nid])+s)
        else:
            if i+2 < n:
                dp[i+2][1] = min(dp[i+2][1],abs(i+2-l[nid])+s)
    # print(i,dp[i])

score = min(score,min(dp[-1]),min(dp[-2]))
print(ans,score)
0