結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
コンテスト
ユーザー alpha_virginis
提出日時 2016-02-25 00:22:07
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,471 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 539 ms
コンパイル使用メモリ 89,120 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-10 01:27:39
合計ジャッジ時間 1,577 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

template<typename T>
class Vector2 {
public:
  Vector2(){}
  Vector2(T x_, T y_) : x(x_), y(y_) {}
  T Norm2();
  T x, y;
};

template<typename T> Vector2<T> operator + (const Vector2<T>& left, const Vector2<T>& right) {
  return Vector2<T>(left.x + right.x, left.y + right.y);
}

template<typename T> Vector2<T> operator - (const Vector2<T>& left, const Vector2<T>& right) {
  return Vector2<T>(left.x - right.x, left.y - right.y);
}

template<typename T>
T Vector2<T>::Norm2() {
  return x * x + y * y;
}

int main() {

  Vector2<int> p[3];
  scanf("%d %d", &p[0].x, &p[0].y);
  scanf("%d %d", &p[1].x, &p[1].y);
  scanf("%d %d", &p[2].x, &p[2].y);

  Vector2<int> v[3][3];
  for(int i = 0; i < 3; ++i) {
    for(int j = 0; j < 3; ++j) {
      v[i][j] = p[j] - p[i];
    }
  }

  Vector2<int> res;
  bool exist = false;
  if( v[0][1].Norm2() == v[0][2].Norm2() and v[0][1].Norm2() * 2 == v[1][2].Norm2() ) {
    res = p[2] + p[1] - p[0]; exist = true;
  }
  if( v[1][0].Norm2() == v[1][2].Norm2() and v[1][0].Norm2() * 2 == v[0][2].Norm2() ) {
    res = p[2] + p[0] - p[1]; exist = true;
  }
  if( v[2][0].Norm2() == v[2][1].Norm2() and v[2][0].Norm2() * 2 == v[0][1].Norm2() ) {
    res = p[1] + p[0] - p[2]; exist = true;
  }

  if( exist ) {
    printf("%d %d\n", res.x, res.y);
  }
  else {
    printf("-1\n");
  }    
  
  return 0;
}
0