Problem p03265 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

llong pow(int x, int n) {
  llong ans = x;
  if (n == 0)
    return 1;

  for (int i = 0; i < n - 1; i++) {
    ans *= x;
  }

  return ans;
}

template <typename T> struct BIT { // 1-indexed
private:
  vector<T> array;
  const int n;

public:
  // 初期化
  BIT(int _n) : array(_n + 1, 0), n(_n) {}

  // 1番目からi番目までの累積和を求める
  T sum(int i) {
    T s = 0;
    while (i > 0) {
      s += array[i];
      i -= i & -i; // LSB減算
    }

    return s;
  }

  // [i, j]の要素の総和
  T sum(int i, int j) {
    T ret_i = sum(i - 1);
    T ret_j = sum(j);

    return ret_j - ret_i;
  }

  // i番目に要素xを追加
  void add(int i, T x) {
    while (i <= n) {
      array[i] += x;
      i += i & -i; // LSB加算
    }
  }
};

template <typename T> struct BIT2 { // 1-indexed
private:
  vector<vector<T>> array;
  const int n;
  const int m;

public:
  // 初期化
  BIT2(int _n, int _m) : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}

  // (1, 1)から(x, y)までの累積和を求める
  T sum(int x, int y) {
    T s = 0;
    for (int i = x; i > 0; i -= i & (-i)) {
      for (int j = y; j > 0; j -= j & (-j)) {
        s += array[i][j];
      }
    }

    return s;
  }

  // [(x1, y1), (x2, y2)]の要素の総和
  T sum(int x1, int y1, int x2, int y2) {
    return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) +
           sum(x1 - 1, y1 - 1);
  }

  // (x, y)に要素kを追加
  void add(int x, int y, T k) {
    for (int i = x; i <= n; i += i & (-i)) {
      for (int j = y; j <= m; j += j & (-j)) {
        array[i][j] += k;
      }
    }
  }
};

void swap(int *X, int *Y) {
  int t = *X;
  *X = *Y;
  *Y = t;
}

string toUpper(string s) {
  string t = s;
  REP(i, s.size()) { t[i] = toupper(s[i]); }
  return t;
}

string toLower(string s) {
  string t = s;
  REP(i, s.size()) { t[i] = tolower(s[i]); }
  return t;
}

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  vector<int> X3, Y3;
  for (int x = -200; x < 200; ++x) {
    for (int y = -200; y < 200; ++y) {
      if (sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)) ==
          sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))) {
        if (sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)) ==
            sqrt(2) * sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))) {
          X3.push_back(x);
          Y3.push_back(y);
        }
      }
    }
  }

  vector<int> X4, Y4;
  for (int x = -200; x < 200; ++x) {
    for (int y = -200; y < 200; ++y) {
      if (sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)) ==
          sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))) {
        if (sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)) ==
            sqrt(2) * sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))) {
          X4.push_back(x);
          Y4.push_back(y);
        }
      }
    }
  }

  if (x2 < x1 || y1 < y2) {
    cout << X3[0] << " " << Y3[0] << " " << X4[0] << " " << Y4[0] << endl;
  } else {
    cout << X3[1] << " " << Y3[1] << " " << X4[1] << " " << Y4[1] << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

llong pow(int x, int n) {
  llong ans = x;
  if (n == 0)
    return 1;

  for (int i = 0; i < n - 1; i++) {
    ans *= x;
  }

  return ans;
}

template <typename T> struct BIT { // 1-indexed
private:
  vector<T> array;
  const int n;

public:
  // 初期化
  BIT(int _n) : array(_n + 1, 0), n(_n) {}

  // 1番目からi番目までの累積和を求める
  T sum(int i) {
    T s = 0;
    while (i > 0) {
      s += array[i];
      i -= i & -i; // LSB減算
    }

    return s;
  }

  // [i, j]の要素の総和
  T sum(int i, int j) {
    T ret_i = sum(i - 1);
    T ret_j = sum(j);

    return ret_j - ret_i;
  }

  // i番目に要素xを追加
  void add(int i, T x) {
    while (i <= n) {
      array[i] += x;
      i += i & -i; // LSB加算
    }
  }
};

template <typename T> struct BIT2 { // 1-indexed
private:
  vector<vector<T>> array;
  const int n;
  const int m;

public:
  // 初期化
  BIT2(int _n, int _m) : array(_n + 1, vector<T>(_m + 1, 0)), n(_n), m(_m) {}

  // (1, 1)から(x, y)までの累積和を求める
  T sum(int x, int y) {
    T s = 0;
    for (int i = x; i > 0; i -= i & (-i)) {
      for (int j = y; j > 0; j -= j & (-j)) {
        s += array[i][j];
      }
    }

    return s;
  }

  // [(x1, y1), (x2, y2)]の要素の総和
  T sum(int x1, int y1, int x2, int y2) {
    return sum(x2, y2) - sum(x1 - 1, y2) - sum(x2, y1 - 1) +
           sum(x1 - 1, y1 - 1);
  }

  // (x, y)に要素kを追加
  void add(int x, int y, T k) {
    for (int i = x; i <= n; i += i & (-i)) {
      for (int j = y; j <= m; j += j & (-j)) {
        array[i][j] += k;
      }
    }
  }
};

void swap(int *X, int *Y) {
  int t = *X;
  *X = *Y;
  *Y = t;
}

string toUpper(string s) {
  string t = s;
  REP(i, s.size()) { t[i] = toupper(s[i]); }
  return t;
}

string toLower(string s) {
  string t = s;
  REP(i, s.size()) { t[i] = tolower(s[i]); }
  return t;
}

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2 - x1;
  int y = y2 - y1;
  cout << (x2 - y) << " " << (y2 + x) << " " << (x1 - y) << " " << (y1 + x)
       << endl;

  return 0;
}