結果

問題 No.2029 Swap Min Max Min
ユーザー simansiman
提出日時 2022-08-09 16:58:22
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 39,228 KB
最終ジャッジ日時 2023-10-20 01:59:51
合計ジャッジ時間 10,992 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
16,096 KB
testcase_01 AC 84 ms
16,096 KB
testcase_02 AC 84 ms
16,096 KB
testcase_03 AC 188 ms
28,760 KB
testcase_04 AC 114 ms
19,360 KB
testcase_05 AC 118 ms
20,348 KB
testcase_06 AC 153 ms
25,160 KB
testcase_07 AC 200 ms
30,384 KB
testcase_08 AC 243 ms
35,700 KB
testcase_09 AC 130 ms
21,432 KB
testcase_10 AC 106 ms
18,344 KB
testcase_11 AC 146 ms
23,496 KB
testcase_12 AC 127 ms
21,732 KB
testcase_13 AC 253 ms
36,908 KB
testcase_14 AC 182 ms
29,296 KB
testcase_15 AC 260 ms
38,112 KB
testcase_16 AC 183 ms
29,028 KB
testcase_17 AC 252 ms
36,712 KB
testcase_18 AC 272 ms
39,228 KB
testcase_19 AC 185 ms
29,172 KB
testcase_20 AC 185 ms
29,304 KB
testcase_21 AC 184 ms
29,184 KB
testcase_22 AC 184 ms
29,016 KB
testcase_23 AC 266 ms
39,228 KB
testcase_24 AC 267 ms
39,228 KB
testcase_25 AC 185 ms
29,604 KB
testcase_26 AC 183 ms
29,608 KB
testcase_27 WA -
testcase_28 AC 84 ms
16,096 KB
testcase_29 AC 84 ms
16,096 KB
testcase_30 AC 84 ms
16,096 KB
testcase_31 AC 84 ms
16,096 KB
testcase_32 AC 86 ms
16,096 KB
testcase_33 AC 84 ms
16,096 KB
testcase_34 AC 84 ms
16,096 KB
testcase_35 AC 85 ms
16,096 KB
testcase_36 AC 84 ms
16,096 KB
testcase_37 AC 84 ms
16,096 KB
testcase_38 AC 246 ms
35,976 KB
testcase_39 AC 182 ms
29,172 KB
testcase_40 AC 174 ms
27,792 KB
testcase_41 AC 251 ms
37,180 KB
testcase_42 AC 252 ms
37,272 KB
testcase_43 AC 178 ms
28,828 KB
testcase_44 AC 264 ms
39,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)

if N == 2
  puts 0
  exit
end

x = N / 2
pos = []

N.times do |i|
  a = A[i]
  pos << i if a <= x
end

if N % 2 == 0
  dp = Array.new(N) { Array.new(2, Float::INFINITY) }
  dp[0][0] = pos[0]
  dp[0][1] = (pos[0] - 1).abs
  div = N / 2

  1.upto(div - 1) do |d|
    cur = 2 * d + 1
    v = pos[d]
    dp[d][0] = [dp[d - 1][0] + (cur - 1 - v).abs, dp[d - 1][1] + (cur - 1 - v).abs].min
    dp[d][1] = dp[d - 1][1] + (cur - v).abs
  end

  y = dp[div - 1].min
  puts [x, y].join(' ')
else
  y = 0
  cur = 1

  pos.each do |v|
    y += (cur - v).abs
    cur += 2
  end

  puts [x, y].join(' ')
end
0