結果

問題 No.461 三角形はいくつ?
ユーザー te-shte-sh
提出日時 2017-12-15 18:13:18
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,099 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 93,636 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-09-03 17:37:57
合計ジャッジ時間 6,425 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
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 AC 8 ms
4,384 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 173 ms
4,380 KB
testcase_19 AC 178 ms
4,384 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 102 ms
4,380 KB
testcase_26 AC 103 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 264 ms
4,380 KB
testcase_30 AC 250 ms
4,384 KB
testcase_31 AC 265 ms
4,376 KB
testcase_32 AC 265 ms
4,380 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 4 ms
4,384 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!int;
  auto f = new Frac[][](3);
  foreach (i; 0..n) {
    auto rd = readln.splitter;
    auto p = rd.front.to!int; rd.popFront();
    auto a = rd.front.to!int; rd.popFront();
    auto b = rd.front.to!int;
    f[p] ~= Frac(b, a+b);
  }

  foreach (i; 0..3) {
    f[i] ~= Frac(0, 1);
    f[i] = f[i].sort().uniq.array;
  }

  auto ans = 0L, u = Frac(1, 1);
  foreach (f0; f[0])
    foreach (f1; f[1]) {
      if (f0+f1 > u) continue;
      ans += f[2].length;
      ans -= f[2].assumeSorted.equalRange(u-f0-f1).length;
      ans -= f[2].assumeSorted.upperBound(u-f0).length;
      ans -= f[2].assumeSorted.upperBound(u-f1).length;
    }

  writeln(ans);
}

struct Frac
{
  long num, den;

  auto opCmp(Frac rhs)
  {
    return num * rhs.den - rhs.num * den;
  }

  auto opBinary(string op: "+")(Frac rhs)
  {
    return Frac(num * rhs.den + rhs.num * den, den * rhs.den);
  }

  auto opBinary(string op: "-")(Frac rhs)
  {
    return Frac(num * rhs.den - rhs.num * den, den * rhs.den);
  }
}
0