結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー 佐藤淳平佐藤淳平
提出日時 2019-09-08 21:36:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,662 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 146,800 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 22:44:55
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int distSquare (int x1, int y1, int x2, int y2) {
    int d = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
    return d;
}

vector<int> calc(int x1, int y1, int x2, int y2, int x3, int y3) {
    int x4 = x1 + x3 - x2;
    int y4 = y1 + y3 - y2;
    return vector<int> {x4, y4};
}

int main() {
    int X1,X2,X3,Y1,Y2,Y3;
    cin >> X1 >> Y1 >> X2 >> Y2 >> X3 >> Y3;
    int d12, d23, d31;
    d12 = distSquare(X1, Y1, X2, Y2);
    d23 = distSquare(X2, Y2, X3, Y3);
    d31 = distSquare(X3, Y3, X1, Y1);
    if (d12 != d23 && d23 != d31 && d31 != d12) {
        cout << -1 << endl;
        return 0;
    }
    if (d12 == d23 && d23 == d31 && d31 == d12) {
        cout << -1 << endl;
        return 0;
    }
    if (d12 == d23) {
        bool is = ((X2 - X1) * (X3 - X2) + (Y2 - Y1) * (Y3 - Y2) == 0);
        if (is) {
            auto ans = calc(X1, Y1, X2, Y2, X3, Y3);
            cout << ans[0] << " " << ans[1] << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
    
    if (d23 == d31) {
        bool is = ((X3 - X2) * (X1 - X3) + (Y3 - Y2) * (Y1 - Y3) == 0);
        if (is) {
            auto ans = calc(X2, Y2, X3, Y3, X1, Y1);
            cout << ans[0] << " " << ans[1] << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    if (d31 == d12) {
        bool is = ((X1 - X3) * (X2 - X1) + (Y1 - Y3) * (Y2 - Y1) == 0);
        if (is) {
            auto ans = calc(X3, Y3, X1, Y1, X2, Y2);
            cout << ans[0] << " " << ans[1] << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }
}
0