Problem p03245 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n)                                        \
  for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v)                                                               \
  for (size_t I = 0; I < v.size(); ++I) {                                      \
    cout << " " << #v << "[" << I << "]=" << v[I];                             \
  }                                                                            \
  cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pll = pair<lint, lint>;

int main(void) {
  lint n;
  cin >> n;
  vector<lint> x(n), y(n);
  repeat(i, n) cin >> x[i] >> y[i];

  lint parity = abs(x[0]) + abs(y[0]);
  parity %= 2;

  repeat(i, n) {
    lint cand = abs(x[i]) + abs(y[i]);
    cand %= 2;
    if (parity != cand) {
      cout << -1 << endl;
      return 0;
    }
  }

  const lint m = 4;
  cout << (parity == 1 ? m : (m + 1)) << endl;
  vector<lint> d(m);
  repeat_reverse_from_to(i, m - 1, 0) { d[m - 1 - i] = (1 << i); }
  if (parity == 0) {
    d.push_back(1);
  }
  repeat_reverse_from_to(i, d.size() - 1, 0) { cout << d[i] << " "; }
  cout << endl;

  auto dist = [](pll p) -> lint { return abs(p.fst) + abs(p.snd); };

  auto f = [&dist](pll p, lint d, char &c) -> pll {
    pll res = make_pair(1e10, 1e10);
    vector<lint> dx{1, 0, -1, 0};
    vector<lint> dy{0, 1, 0, -1};
    repeat(i, 4) {
      pll cand = make_pair(p.fst + dx[i] * d, p.snd + dy[i] * d);
      if (dist(cand) < dist(res)) {
        res = cand;
        if (i == 0)
          c = 'L';
        if (i == 1)
          c = 'D';
        if (i == 2)
          c = 'R';
        if (i == 3)
          c = 'U';
      }
    }
    return res;
  };

  repeat(i, n) {
    pll p = make_pair(x[i], y[i]);
    string str;
    repeat(j, d.size()) {
      // pdump(p); dump(j); dump(d[j]); el;
      char c;
      p = f(p, d[j], c);
      str += c;
    }
    reverse(str.begin(), str.end());
    cout << str << endl;
    assert(p.fst == 0 and p.snd == 0);
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for (lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for (lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for (lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for (lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for (lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n)                                        \
  for (lint i = (m); (i) >= (lint)(n); --(i))
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define pdump(p) cout << " " << #p << "=(" << p.fst << "," << p.snd << ")"
#define vdump(v)                                                               \
  for (size_t I = 0; I < v.size(); ++I) {                                      \
    cout << " " << #v << "[" << I << "]=" << v[I];                             \
  }                                                                            \
  cout << endl
using namespace std;
using lint = long long;
using ld = long double;
using pll = pair<lint, lint>;

int main(void) {
  lint n;
  cin >> n;
  vector<lint> x(n), y(n);
  repeat(i, n) cin >> x[i] >> y[i];

  lint parity = abs(x[0]) + abs(y[0]);
  parity %= 2;

  repeat(i, n) {
    lint cand = abs(x[i]) + abs(y[i]);
    cand %= 2;
    if (parity != cand) {
      cout << -1 << endl;
      return 0;
    }
  }

  const lint m = 31;
  cout << (parity == 1 ? m : (m + 1)) << endl;
  vector<lint> d(m);
  repeat_reverse_from_to(i, m - 1, 0) { d[m - 1 - i] = (1 << i); }
  if (parity == 0) {
    d.push_back(1);
  }
  repeat_reverse_from_to(i, d.size() - 1, 0) { cout << d[i] << " "; }
  cout << endl;

  auto dist = [](pll p) -> lint { return abs(p.fst) + abs(p.snd); };

  auto f = [&dist](pll p, lint d, char &c) -> pll {
    pll res = make_pair(1e10, 1e10);
    vector<lint> dx{1, 0, -1, 0};
    vector<lint> dy{0, 1, 0, -1};
    repeat(i, 4) {
      pll cand = make_pair(p.fst + dx[i] * d, p.snd + dy[i] * d);
      if (dist(cand) < dist(res)) {
        res = cand;
        if (i == 0)
          c = 'L';
        if (i == 1)
          c = 'D';
        if (i == 2)
          c = 'R';
        if (i == 3)
          c = 'U';
      }
    }
    return res;
  };

  repeat(i, n) {
    pll p = make_pair(x[i], y[i]);
    string str;
    repeat(j, d.size()) {
      // pdump(p); dump(j); dump(d[j]); el;
      char c;
      p = f(p, d[j], c);
      str += c;
    }
    reverse(str.begin(), str.end());
    cout << str << endl;
    assert(p.fst == 0 and p.snd == 0);
  }
}