結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー te-shte-sh
提出日時 2016-08-29 14:14:49
言語 D
(dmd 2.106.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,173 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 172,592 KB
最終ジャッジ日時 2024-04-27 02:22:05
合計ジャッジ時間 855 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.d(18): Error: no property `x` for `r` of type `std.typecons.Nullable!(Tuple!(int, "x", int, "y"))`
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/typecons.d(3238):        struct `Nullable` defined here
Main.d(18): Error: no property `y` for `r` of type `std.typecons.Nullable!(Tuple!(int, "x", int, "y"))`
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/typecons.d(3238):        struct `Nullable` defined here

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv, std.math;
import std.stdio, std.typecons;

alias Tuple!(int, "x", int, "y") point;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto p1 = point(rd[0], rd[1]);
  auto p2 = point(rd[2], rd[3]);
  auto p3 = point(rd[4], rd[5]);

  auto r = call(p1, p2, p3);
  if (r.isNull)
    writeln(-1);
  else
    writeln(r.x, " ", r.y);
}

Nullable!point call(point p1, point p2, point p3)
{
  foreach (ps; [tuple(p1, p2, p3), tuple(p2, p3, p1), tuple(p3, p1, p2)]) {
    auto r = calc(ps.expand);
    if (!r.isNull)
      return r;
  }
  return Nullable!point.init;
}

Nullable!point calc(point p1, point p2, point p3)
{
  auto v12 = point(p1.x - p2.x, p1.y - p2.y);
  auto v23 = point(p2.x - p3.x, p2.y - p3.y);
  if (vabs(v12) == vabs(v23) && vinner_prod(v12, v23) == 0) {
    auto pc = point((p1.x + p3.x) / 2, (p1.y + p3.y) / 2);
    return Nullable!point(point(p1.x + p3.x - p2.x, p1.y + p3.y - p2.y));
  } else {
    return Nullable!point.init;
  }
}

int vabs(point v)
{
  return v.x ^^ 2 + v.y ^^ 2;
}

int vinner_prod(point v1, point v2)
{
  return v1.x * v2.x + v1.y * v2.y;
}
0