結果

問題 No.1374 Absolute Game
ユーザー yuruhiyayuruhiya
提出日時 2021-02-06 07:27:50
言語 Crystal
(1.11.2)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 364 bytes
コンパイル時間 24,031 ms
コンパイル使用メモリ 256,524 KB
実行使用メモリ 11,932 KB
最終ジャッジ日時 2023-09-15 11:58:48
合計ジャッジ時間 26,211 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 3 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 3 ms
4,400 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 3 ms
4,448 KB
testcase_07 AC 2 ms
4,512 KB
testcase_08 AC 11 ms
6,728 KB
testcase_09 AC 26 ms
9,548 KB
testcase_10 AC 29 ms
10,140 KB
testcase_11 AC 19 ms
8,716 KB
testcase_12 AC 12 ms
6,832 KB
testcase_13 AC 23 ms
9,816 KB
testcase_14 AC 33 ms
11,808 KB
testcase_15 AC 33 ms
11,892 KB
testcase_16 AC 33 ms
11,772 KB
testcase_17 AC 33 ms
11,856 KB
testcase_18 AC 33 ms
11,784 KB
testcase_19 AC 33 ms
11,932 KB
testcase_20 AC 13 ms
7,116 KB
testcase_21 AC 17 ms
8,452 KB
testcase_22 AC 30 ms
10,808 KB
testcase_23 AC 6 ms
5,240 KB
testcase_24 AC 7 ms
5,628 KB
testcase_25 AC 8 ms
5,780 KB
testcase_26 AC 12 ms
6,828 KB
testcase_27 AC 16 ms
7,472 KB
権限があれば一括ダウンロードができます

ソースコード

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 solve(a)
  s = [0i64, 0i64]
  i = 0
  until a.empty?
    s[i % 2] += a.pop
    i += 1
  end
  s[0].abs - s[1].abs
end

n = read_line.to_i
a = read_line.split.map(&.to_i64)
a.map! { |i| -i } if a.sum < 0
a.sort!
puts solve(a)
0