Problem p03594 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args> auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename() const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll H, ll W, ll d) {
  vector<string> res(H, string(W, '.'));
  if (d % 2 == 1) {
    REP(i, H) REP(j, W) { res[i][j] = ((i + j) % 2 ? 'R' : 'Y'); }
  } else {

    assert(false);
  }
  REP(i, H) cout << res[i] << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
  ll H;
  ll d;
  ll W;
  scanf("%lld", &H);
  scanf("%lld", &W);
  scanf("%lld", &d);
  solve(H, W, d);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args> auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename() const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll H, ll W, ll d) {
  vector<string> res(H, string(W, '.'));
  if (d % 2 == 1) {
    REP(i, H) REP(j, W) { res[i][j] = ((i + j) % 2 ? 'R' : 'Y'); }
  } else {
    REP(i, H) REP(j, W) {
      int jj = j + (i + j) % 2;
      int x = (i - jj + 2000) / 2;
      int y = (i + jj) / 2;
      x /= (d / 2);
      y /= (d / 2);
      x = x % 2;
      y = y % 2;
      // cout << x * 2 + y << endl;
      res[i][j] = "RYBG"[x * 2 + y];
    }
  }
  REP(i, H) cout << res[i] << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
  ll H;
  ll d;
  ll W;
  scanf("%lld", &H);
  scanf("%lld", &W);
  scanf("%lld", &d);
  solve(H, W, d);
  return 0;
}