結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー PachicobuePachicobue
提出日時 2017-07-14 19:23:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,192 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 167,684 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 19:51:06
合計ジャッジ時間 2,577 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

struct Vec {
    Vec() = default;
    Vec(int x, int y) : dx(x), dy(y) {}
    Vec(const Vec& v) : dx(v.dx), dy(v.dy)
    {
    }
    int dx;
    int dy;
    int normSq() const
    {
        return dx * dx + dy * dy;
    }
    int product(const Vec& v) const
    {
        return dx * v.dx + dy * v.dy;
    }
    Vec operator+(const Vec& v) const
    {
        return Vec{dx + v.dx, dy + v.dy};
    }
    Vec operator-(const Vec& v) const
    {
        return Vec{dx - v.dx, dy - v.dy};
    }
    bool operator<(const Vec& v) const
    {
        return normSq() > v.normSq();
    }
};

int main()
{
    Vec pos[3];
    for (ll i = 0; i < 3; i++) {
        cin >> pos[i].dx >> pos[i].dy;
    }
    pair<Vec, int> v_[3];
    v_[0].first = pos[1] - pos[0];
    v_[1].first = pos[2] - pos[1];
    v_[2].first = pos[0] - pos[2];
    v_[0].second = 0;
    v_[1].second = 1;
    v_[2].second = 2;
    pair<Vec, int> v[3];
    v[0] = v_[0];
    v[1] = v_[1];
    v[2] = v_[2];
    sort(v, v + 3);
    if (v[1].first.product(v[2].first) == 0 and v[1].first.normSq() == v[2].first.normSq()) {
        Vec ans;
        if (v[0].second == 0) {
            ans = pos[0] - v_[1].first;
            cout << ans.dx << " " << ans.dy << endl;
        } else if (v[0].second == 1) {
            ans = pos[1] - v_[2].first;
            cout << ans.dx << " " << ans.dy << endl;
        } else {
            ans = pos[2] - v_[0].first;
            cout << ans.dx << " " << ans.dy << endl;
        }
    } else {
        cout << -1 << endl;
    }

    return 0;
}
0