結果

問題 No.178 美しいWhitespace (1)
ユーザー te-sh
提出日時 2016-08-31 15:41:05
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 127,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 04:01:37
合計ジャッジ時間 1,586 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.numeric, std.math, std.bigint, std.bitmanip, std.random;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!long;
  auto abi = iota(n)
    .map!(_ => readln.split.map!(to!long))
    .map!(rd => tuple(rd[0], rd[1]));

  auto li = abi.map!(ab => ab[0] + 4 * ab[1]).array;
  li.sort!("a > b");

  writeln(calc(li));
}

long calc(long[] li)
{
  auto r = 0L;
  auto m = li.front;
  foreach (l; li)
    if ((m - l) % 2 == 1)
      return -1;
    else
      r += (m - l) / 2;

  return r;
}
0