結果

問題 No.1374 Absolute Game
ユーザー yuruhiyayuruhiya
提出日時 2021-02-05 22:34:47
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 623 bytes
コンパイル時間 23,860 ms
コンパイル使用メモリ 259,176 KB
実行使用メモリ 12,176 KB
最終ジャッジ日時 2023-09-15 09:04:56
合計ジャッジ時間 20,648 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,512 KB
testcase_01 AC 3 ms
4,412 KB
testcase_02 AC 3 ms
4,416 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 2 ms
4,448 KB
testcase_06 AC 3 ms
4,400 KB
testcase_07 AC 2 ms
4,452 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

def solve1(a)
  s = [0i64, 0i64]
  i = 0
  until a.empty?
    s[i % 2] += a.pop
    i += 1
  end
  s[0].abs - s[1].abs
end

def solve2(a)
  s = [0i64, 0i64]
  i = 0
  until a.empty?
    if i.even?
      s[0] += a.pop
    else
      s[1] += a.shift
    end
    i += 1
  end
  s[0].abs - s[1].abs
end

n = read_line.to_i
a = read_line.split.map(&.to_i).sort
puts [solve1(Deque.new(a)),
      solve1(Deque.new(a.reverse)),
      solve2(Deque.new(a)),
      solve2(Deque.new(a.reverse))].max
0