Problem p03247 (C++)

Buggy submission (status: Runtime Error):
#define DEB
#include <bits/stdc++.h>
#define REP(i, m) for (int i = 0; i < (m); ++i)
#define REPN(i, m, in) for (int i = (in); i < (m); ++i)
#define ALL(t) (t).begin(), (t).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr << "called:" << __LINE__ << endl
#define dumpR(x) cerr << "\x1b[31m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpY(x) cerr << "\x1b[33m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpG(x) cerr << "\x1b[32m" << #x << " = " << (x) << "\x1b[39m" << endl
template <class T> void debug(T a, T b) {
  for (; a != b; ++a)
    cerr << *a << ' ';
  cerr << endl;
}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template <class T> void debug(T a, T b) { ; }
#endif

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

typedef long long int lint;
typedef pair<lint, lint> pi;

namespace std {
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
  out << '(' << a.fr << ',' << a.sc << ')';
  return out;
}
} // namespace std

// const int INF=5e8;
int n;
pi ps[1005];
void ng() {
  puts("-1");
  exit(0);
}

int main() {
  cin >> n;
  int cnt = 0;
  REP(i, n) {
    cin >> ps[i].fr >> ps[i].sc;
    if ((abs(ps[i].fr) + abs(ps[i].sc)) % 2 !=
        (abs(ps[0].fr) + abs(ps[0].sc)) % 2) {
      ng();
    }
  }
  vector<lint> d;
  REP(i, 32) { d.pb(1ll << (i + 1)); }
  lint tot = accumulate(ALL(d), 0ll);
  bool type = false;
  if ((abs(ps[0].fr) + abs(ps[0].sc)) % 2 == 0) {
    d.pb(1);
    d.pb(1);
  } else {
    d.pb(1);
    type = true;
  }
  int m = d.size();
  cout << d.size() << endl;
  for (auto e : d)
    cout << e << " ";
  puts("");

  REP(i, n) {
    string res(m, ' ');
    lint xx = ps[i].fr, yy = ps[i].sc;
    if (abs(yy) & 1) {
      if (abs(xx + yy - 1) % 4 != 0) {
        --yy;
        res[m - 1] = 'U';
      } else {
        ++yy;
        res[m - 1] = 'D';
      }
    }
    if (abs(xx) & 1) {
      if (abs(xx + yy - 1) % 4 != 0) {
        --xx;
        if (type)
          res[m - 1] = 'R';
        else
          res[m - 2] = 'R';
      } else {
        ++xx;
        if (type)
          res[m - 1] = 'L';
        else
          res[m - 2] = 'L';
      }
    }

    if (!type && res[m - 1] == ' ') {
      res[m - 1] = 'L';
      res[m - 2] = 'R';
    }
    dump(xx);
    dump(yy);

    lint x = (xx + yy), y = (xx - yy);
    x += tot;
    y += tot;
    assert(x % 4 == 0);
    assert(y % 4 == 0);
    dump(x);
    dump(y);

    int idx = 0;
    for (auto e : d)
      if (e != 1) {
        int bit = 0;
        if (x & (e * 2))
          bit |= 2;
        if (y & (e * 2))
          bit |= 1;

        string code = "LDUR";
        res[idx] = code[bit];
        ++idx;
      }
    cout << res << endl;
  }
  return 0;
}


Fixed submission:
#define DEB
#include <bits/stdc++.h>
#define REP(i, m) for (int i = 0; i < (m); ++i)
#define REPN(i, m, in) for (int i = (in); i < (m); ++i)
#define ALL(t) (t).begin(), (t).end()
#define CLR(a) memset((a), 0, sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifdef DEB
#define dump(x) cerr << #x << " = " << (x) << endl
#define prl cerr << "called:" << __LINE__ << endl
#define dumpR(x) cerr << "\x1b[31m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpY(x) cerr << "\x1b[33m" << #x << " = " << (x) << "\x1b[39m" << endl
#define dumpG(x) cerr << "\x1b[32m" << #x << " = " << (x) << "\x1b[39m" << endl
template <class T> void debug(T a, T b) {
  for (; a != b; ++a)
    cerr << *a << ' ';
  cerr << endl;
}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template <class T> void debug(T a, T b) { ; }
#endif

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

typedef long long int lint;
typedef pair<lint, lint> pi;

namespace std {
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
  out << '(' << a.fr << ',' << a.sc << ')';
  return out;
}
} // namespace std

// const int INF=5e8;
int n;
pi ps[1005];
void ng() {
  puts("-1");
  exit(0);
}

int main() {
  cin >> n;
  int cnt = 0;
  REP(i, n) {
    cin >> ps[i].fr >> ps[i].sc;
    if ((abs(ps[i].fr) + abs(ps[i].sc)) % 2 !=
        (abs(ps[0].fr) + abs(ps[0].sc)) % 2) {
      ng();
    }
  }
  vector<lint> d;
  REP(i, 32) { d.pb(1ll << (i + 1)); }
  lint tot = accumulate(ALL(d), 0ll);
  bool type = false;
  if ((abs(ps[0].fr) + abs(ps[0].sc)) % 2 == 0) {
    d.pb(1);
    d.pb(1);
  } else {
    d.pb(1);
    type = true;
  }
  int m = d.size();
  cout << d.size() << endl;
  for (auto e : d)
    cout << e << " ";
  puts("");

  REP(i, n) {
    string res(m, ' ');
    lint xx = ps[i].fr, yy = ps[i].sc;
    if (abs(yy) & 1) {
      if (abs(xx + yy - 1) % 4 != 0) {
        --yy;
        res[m - 1] = 'U';
      } else {
        ++yy;
        res[m - 1] = 'D';
      }
    }
    if (abs(xx) & 1) {
      if (abs(xx + yy - 1) % 4 != 0) {
        --xx;
        if (type)
          res[m - 1] = 'R';
        else
          res[m - 2] = 'R';
      } else {
        ++xx;
        if (type)
          res[m - 1] = 'L';
        else
          res[m - 2] = 'L';
      }
    }

    if (!type && res[m - 1] == ' ') {
      if (abs(xx + yy) % 4 != 0) {
        res[m - 1] = 'L';
        res[m - 2] = 'R';
      } else {
        res[m - 1] = res[m - 2] = 'L';
        xx += 2;
      }
    }
    dump(xx);
    dump(yy);

    lint x = (xx + yy), y = (xx - yy);
    x += tot;
    y += tot;
    assert(x % 4 == 0);
    assert(y % 4 == 0);
    dump(x);
    dump(y);

    int idx = 0;
    for (auto e : d)
      if (e != 1) {
        int bit = 0;
        if (x & (e * 2))
          bit |= 2;
        if (y & (e * 2))
          bit |= 1;

        string code = "LDUR";
        res[idx] = code[bit];
        ++idx;
      }
    cout << res << endl;
  }
  return 0;
}