結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-08 22:32:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,614 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 172,072 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 03:09:25
合計ジャッジ時間 2,651 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int intpow(int a, int b) {
    int ans = 1;
    while (b) {
        if (b & 1)
            ans *= a;
        a *= a;
        b /= 2;
    }
    return ans;
}


int len_sqrt(vector<pair<int, int>>& V, int i) {
    return intpow(abs(V[i].first - V[(i + 1) % 4].first), 2) + intpow(abs(V[i].second - V[(i + 1) % 4].second), 2);
}

bool check(vector<pair<int, int>> V) {
    if (
        len_sqrt(V, 0) == len_sqrt(V, 1) && len_sqrt(V, 1) == len_sqrt(V, 2) && len_sqrt(V, 2) == len_sqrt(V, 3) && V[0] != V[2] && V[1] != V[3] && (V[1].first - V[0].first) * (V[3].first - V[0].first) + (V[1].second - V[0].second) * (V[3].second - V[0].second) == 0) {
        return true;
    }
    return false;
}

int main() {
    vector<pair<int, int>> V(4);
    for (int i = 0; i < 3; i++) {
        int X, Y;
        cin >> X >> Y;
        V[i] = {X, Y};
    }

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (i == j) continue;

            V[3] = {V[i].first + V[j].first - V[3 - i - j].first,
                V[i].second + V[j].second - V[3 - i - j].second};

            auto V_copy = V;
            sort(V_copy.begin(), V_copy.end());
            bool flag = false;
            do {
                if (check(V_copy)) {
                    flag = true;
                    break;
                };
            } while (next_permutation(V_copy.begin(), V_copy.end()));
            if (flag) {
                cout << V[3].first << " " << V[3].second << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}
0