Problem p02664 (C++) — buggy submission, verdict: Runtime Error

// Postdocs

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a)                                                           \\
  ll n;                                                                        \\
  cin >> n;                                                                    \\
  vector<ll> a(n);                                                             \\
  rep(i, 0, n) cin >> a[i]
#define vecrep(n, a, type)                                                     \\
  vector<type> a(n);                                                           \\
  rep(i, 0, n) cin >> a[i]
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\\n"
#define spa " "
#define cout15(a) printf("%.15f\\n", a)
template <class T> inline bool chmin(T &a, T b, bool f) {
  if (f == 1) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
  } else if (f == 0) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
  }
  return false;
}
typedef pair<ll, string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;         // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18

signed main() {
  string t;
  cin >> t;
  rep(i, 0, t.size()) {
    if (t[i] == '?')
      t[i] = 'D';
  }
  cout << t << nnn;
  return 0;
}

Error: 0

Fixed submission:

// Postdocs

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a)                                                           \\
  ll n;                                                                        \\
  cin >> n;                                                                    \\
  vector<ll> a(n);                                                             \\
  rep(i, 0, n) cin >> a[i]
#define vecrep(n, a, type)                                                     \\
  vector<type> a(n);                                                           \\
  rep(i, 0, n) cin >> a[i]
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\\n"
#define spa " "
#define cout15(a) printf("%.15f\\n", a)
template <class T> inline bool chmin(T &a, T b, bool f) {
  if (f == 1) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
  } else if (f == 0) {
    if (a < b) {
      a = b;
      return true;
    }
    return false;
  }
  return false;
}
typedef pair<ll, string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;         // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18

signed main() {
  string t;
  cin >> t;
  if (t[0] == '?')
    t[0] = 'P';
  if (t[t.size() - 1] == '?')
    t[t.size() - 1] = 'D';
  rep(i, 1, t.size() - 2) {
    if (t[i] == '?') {
      if (t[i - 1] == 'P')
        t[i] = 'D';
      else if (t[i + 1] = 'D')
        t[i] = 'P';
      else
        t[i] = 'P';
    }
  }
  cout << t << nnn;
  return 0;
}