結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー imulanimulan
提出日時 2016-02-05 21:44:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,281 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 158,028 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 22:17:25
合計ジャッジ時間 2,286 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

typedef struct{
  int x,y;
}Point;

int norm(Point p){
  return p.x*p.x+p.y*p.y;
}

int inner(Point p, Point q){
  return p.x*q.x+p.y*q.y;
}

int main(int argc, char const *argv[]) {
  Point p[3];
  rep(i,3) cin >>p[i].x >>p[i].y;

  int dx=p[0].x, dy=p[0].y;
  rep(i,3){
    p[i].x-=dx;
    p[i].y-=dy;
  }

  bool found=false;
  Point ans;
  if(norm(p[1])==norm(p[2])){
    //点1と点2まで距離が等しいなら
    //内積0のとき直角で正方形が存在
    if(inner(p[1],p[2])==0){
      found=true;
      ans.x=p[1].x+p[2].x;
      ans.y=p[1].y+p[2].y;
    }
  }
  else{
    if(norm(p[2])<norm(p[1])) swap(p[1],p[2]);
    //長い方は短い方の2倍
    if(norm(p[1])*2==norm(p[2])){
      if(inner(p[1],p[2])>0){
        if(inner(p[1],p[2])*inner(p[1],p[2])*2 == norm(p[1])*norm(p[2])){
          found=true;
          ans.x=p[2].x-p[1].x;
          ans.y=p[2].y-p[1].y;
        }
      }
    }
  }


  if(!found) printf("-1\n");
  else printf("%d %d\n",ans.x+dx, ans.y+dy);
  
  return 0;
}
0