結果

問題 No.635 自然門松列
ユーザー te-shte-sh
提出日時 2018-01-23 15:01:09
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2 ms / 650 ms
コード長 1,710 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 89,348 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 18:13:36
合計ジャッジ時間 1,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;      // math functions

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;}
T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;}

void main()
{
  int n; readV(n);
  foreach (_; 0..n) writeln(calc ? "YES" : "NO");
}

struct Rg
{
  real a, b;
  static empty() { return Rg(real.nan, real.nan); }
  auto isEmpty() { return a.isNaN; }
  auto opBinary(string op: "&")(Rg r)
  {
    if (isEmpty || r.isEmpty) return Rg.empty;
    auto s = Rg(max(a, r.a), min(b, r.b));
    return s.a >= s.b ? Rg.empty : s;
  }
}

auto calc()
{
  int x1, x2, x3, y1, y2, y3; readV(x1, x2, x3, y1, y2, y3);

  if (x1 == x3 && y1 == y3) return false;

  Rg r1, r2;
  if (y1 == y2) {
    r1 = x2 > x1 ? Rg(-real.infinity, real.infinity) : Rg.empty;
    r2 = x2 < x1 ? Rg(-real.infinity, real.infinity) : Rg.empty;
  } else {
    auto t = -(x1-x2).to!real/(y1-y2);
    r1 = y1 > y2 ? Rg(-real.infinity, t) : Rg(t, real.infinity);
    r2 = y1 > y2 ? Rg(t, real.infinity) : Rg(-real.infinity, t);
  }

  Rg r3, r4;
  if (y3 == y2) {
    r3 = x2 > x3 ? Rg(-real.infinity, real.infinity) : Rg.empty;
    r4 = x2 < x3 ? Rg(-real.infinity, real.infinity) : Rg.empty;
  } else {
    auto t = -(x3-x2).to!real/(y3-y2);
    r3 = y3 > y2 ? Rg(-real.infinity, t) : Rg(t, real.infinity);
    r4 = y3 > y2 ? Rg(t, real.infinity) : Rg(-real.infinity, t);
  }

  auto s1 = r1 & r3, s2 = r2 & r4;
  return !s1.isEmpty && s1.b > 0 || !s2.isEmpty && s2.b > 0;
}
0