alexjercan/bugnet huggingface dataset:
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, b) for (ll i = a; i <= b; i++)
#define rfo(i, n) for (ll i = n - 1; i >= 0; i--)
#define rloop(i, a, b) for (ll i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define precision cout << fixed << setprecision(10)
#define mem(x, p) memset(x, p, sizeof(x))
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define kk "\\n"
#define setbits(x) __builtin_popcountll(x)
const double pi = 3.1415926535897932384626;
// const ll mod = 998244353;
const ll mod = 1e9 + 7;
int main() {
  IOS string s;
  cin >> s;
  ll n = s.length();
  for (ll i = 0; i < n; i++) {
    if (s[i] == '?')
      cout << "D";
    else
      cout << s[i];
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i, n) for (ll i = 0; i < n; i++)
#define loop(i, a, b) for (ll i = a; i <= b; i++)
#define rfo(i, n) for (ll i = n - 1; i >= 0; i--)
#define rloop(i, a, b) for (ll i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define precision cout << fixed << setprecision(10)
#define mem(x, p) memset(x, p, sizeof(x))
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define kk "\\n"
#define setbits(x) __builtin_popcountll(x)
const double pi = 3.1415926535897932384626;
// const ll mod = 998244353;
const ll mod = 1e9 + 7;
int main() {
  IOS string s;
  cin >> s;
  ll n = s.length();
  string ans = "";
  for (ll i = 0; i < n - 1; i++) {
    if (s[i] == '?') {
      if (s[i + 1] == 'D')
        ans = ans + 'P';
      else
        ans = ans + 'D';
    } else
      ans = ans + s[i];
  }
  char ch = (s[n - 1] == '?') ? 'D' : s[n - 1];
  ans = ans + ch;
  cout << ans << kk;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main(void) {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == '?') {
      if (t[i - 1] == 'P') {
        t[i] = 'D';
      } else if (t[i + 1] == 'D') {
        t[i] = 'P';
      } else if (t[i + 1] == 'P') {
        t[i] = 'D';
      } else {
        if (t[i + 1] == '?') {
          if (t[i + 2] == 'D') {
            t[i] = 'D';
            t[i + 1] = 'P';
          } else {
            t[i] = 'P';
            t[i + 1] = 'D';
          }
        } else {
          t[i] = 'D';
        }
      }
    }
  }
  cout << t << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string Ans;
int Score = 0;

int calcPoint(string s) {
  int point = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'D') {
      point++;
    } else {
      if (s[i + 1] == 'D') {
        point++;
      }
    }
  }
  return point;
}

int searchString(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      if (s[i - 1] == 'P') {
        s[i] = 'D';
      } else if (s[i + 1] == 'D') {
        s[i] = 'P';
      } else if (s[i + 1] == 'P') {
        s[i] = 'D';
      } else {
        s[i] = 'P';
        searchString(s);
        s[i] = 'D';
        searchString(s);
        break;
      }
    }
  }
  int p = calcPoint(s);
  if (Score < p) {
    Score = p;
    Ans = s;
  }
  return Score;
}

int main(void) {
  string t;
  cin >> t;
  searchString(t);
  cout << Ans << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T> inline void chkmax(T &x, T y) {
  if (x < y)
    x = y;
}

template <typename T> inline void chkmin(T &x, T y) {
  if (x > y)
    x = y;
}

inline int read() {
#define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48)
    c = nc;
  while (c > 47)
    x = x * 10 + (c ^ 48), c = nc;
  return x;
#undef nc
}

typedef long long ll;
const int maxn = 1e6 + 10;
char str[maxn];

void solve() {
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  int ans = 0;
  rep(i, 1, n) {
    if (str[i] == 'P') {
      putchar('P');
      ans += i < n && str[i + 1] != 'P';
    } else {
      putchar('D');
      ans++;
    }
  }
  //  cout << ans<<endl;
}

int main() {
  //  int T = read();
  //  while (T--) solve();
  solve();
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T> inline void chkmax(T &x, T y) {
  if (x < y)
    x = y;
}

template <typename T> inline void chkmin(T &x, T y) {
  if (x > y)
    x = y;
}

inline int read() {
#define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48)
    c = nc;
  while (c > 47)
    x = x * 10 + (c ^ 48), c = nc;
  return x;
#undef nc
}

typedef long long ll;
const int maxn = 1e5 + 10;
char str[maxn];

void solve() {
  scanf("%s", str + 1);
  int n = strlen(str + 1);
  int ans = 0;
  rep(i, 1, n) {
    if (str[i] == 'P') {
      putchar('P');
      ans += i < n && str[i + 1] != 'P';
    } else {
      putchar('D');
      ans++;
    }
  }
  //  cout << ans<<endl;
}

int main() {
  //  int T = read();
  //  while (T--) solve();
  solve();
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int inf = 1001001001;

int main() {

  string S;
  cin >> S;
  int N = S.size();
  rep(i, N) {
    if (i == 0 && S.at(i) == '?') {
      S.at(i) = 'D';
      continue;
    }

    if (S.at(i) == '?') {
      if (S.at(i - 1) == 'P') {
        S.at(i) = 'D';
      } else {
        S.at(i) = 'D';
      }
    }
  }

  cout << S << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const int inf = 1001001001;

int main() {

  string S;
  cin >> S;
  int N = S.size();
  rep(i, N) {
    if (S.at(i) == '?') {
      if (S.at(i - 1) == 'P') {
        S.at(i) = 'D';
      } else {
        S.at(i) = 'P';
      }
    }
  }

  cout << S << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define sq(x) (x) * (x)
#define PI acos(-1.0)
#define nl '\\n'

typedef long long int ll;
typedef unsigned long long int llu;

int main() {
  faster string s, ans;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      ans += 'D';
    } else
      ans += s[i];
  }
  cout << ans << nl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define sq(x) (x) * (x)
#define PI acos(-1.0)
#define nl '\\n'

typedef long long int ll;
typedef unsigned long long int llu;

int main() {
  faster

      int i,
      j, a, b;
  string s, ans = "";
  cin >> s;
  j = 0;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      ans = ans + 'D';
    } else
      ans = ans + s[i];
  }
  cout << ans << nl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  string s, ans;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == '?')
      ans += 'D';
    else
      ans += s[i];
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, a, b;
  string s, ans = "";
  cin >> s;
  j = 0;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == '?') {
      ans = ans + 'D';
    } else
      ans = ans + s[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main() {
  string t;
  cin >> t;
  int a;
  a = t.length();
  if (t.at(0) == '?') {
    t.at(0) = 'D';
  }

  for (int i = 1; i < a - 1; i++) {
    if (t.at(i) == '?' && t.at(i - 1) == 'D' && t.at(i + 1) == 'D') {
      t.at(i) = 'P';
    }
    if (t.at(i) == '?' && t.at(i - 1) == 'P') {
      t.at(i) = 'D';
    } else if (t.at(i) == '?' && t.at(i + 1) == '?') {
      if (t.at(i - 1) == 'D') {
        t.at(i) = 'P';
        t.at(i + 1) = 'D';
      } else {
        t.at(i) = 'D';
      }

    } else if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  if (t.at(a - 1) == '?') {
    t.at(a - 1) = 'D';
  }

  cout << t << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, x, n) for (int i = x; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main() {
  string t;
  cin >> t;
  int a;
  a = t.length();

  for (int i = 0; i < a - 1; i++) {
    if (t.at(i) == '?' && t.at(i - 1) == 'D' && t.at(i + 1) == 'D') {
      t.at(i) = 'P';
    }
    if (t.at(i) == '?' && t.at(i - 1) == 'P') {
      t.at(i) = 'D';
    } else if (t.at(i) == '?' && t.at(i + 1) == '?') {
      if (t.at(i - 1) == 'D') {
        t.at(i) = 'P';
        t.at(i + 1) = 'D';
      } else {
        t.at(i) = 'D';
      }

    } else if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  if (t.at(a - 1) == '?') {
    t.at(a - 1) = 'D';
  }

  cout << t << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

vector<char> T(200000);
int maxPD = 0;
int len;

int main() {
  string TT;
  cin >> TT;
  len = TT.size();
  for (int i = 0; i < len; i++) {
    T.at(i) = TT.at(i);
    if (TT.at(i) == '?') {
      if (i > 1 && TT.at(i - 1) == 'P')
        T.at(i) = 'D';
      if (i > 1 && TT.at(i - 1) == 'D')
        T.at(i) = 'D';
      T.at(i) = 'D';
    }
  }

  for (int i = 0; i < len; i++) {
    cout << T.at(i);
  }

  cout << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

vector<char> T(200000);
int maxPD = 0;
int len;

int main() {
  string TT;
  cin >> TT;
  len = TT.size();
  for (int i = 0; i < len; i++) {
    T.at(i) = TT.at(i);
    if (TT.at(i) == '?') {
      if (TT.at(i - 1) == 'P')
        T.at(i) = 'D';
      if (TT.at(i - 1) == 'D')
        T.at(i) = 'D';
      T.at(i) = 'D';
    }
  }

  for (int i = 0; i < len; i++) {
    cout << T.at(i);
  }

  cout << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i, n, m) for (lli i = (lli)(n); i < (lli)(m); ++i)
#define reep(i, n, m) for (int i = (int)(n); i <= (int)(m); ++i)
#define per(i, m, n) for (lli i = (int)(m)-1; i >= (int)(n); --i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(), n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(), N.end()), N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K, L, N, S) vector<L> K(N, S)
#define dv(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S))
#define tv(K, L, N, M, R, S)                                                   \\
  vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S)))
#define pint pair<lli, lli>
#define paf(L, R) pair<L, R>
#define maxx 5100000
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define endl "\\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;

  for (int i = 0; i < s.size(); ++i) {

    if (s.at(i) == '?')
      cout << 'D';
    else
      cout << s.at(i);
  }
  cout << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  int len = s.length();
  if (s.at(0) == '?') {
    if (s.at(1) == 'D')
      s.at(0) = 'P';
    else if (s.at(1) == '?')
      s.at(0) = 'P';
    else
      s.at(0) = 'D';
  }
  for (int i = 1; i < len - 2; ++i) {
    if (s.at(i) == '?') {
      if (s.at(i + 1) == '?') {
        if (s.at(i - 1) == 'P') {
          if (s.at(i + 2) == 'P') {
            s.at(i) = 'D';
            s.at(i + 1) = 'D';
          } else {
            s.at(i) = 'D';
            s.at(i + 1) = 'P';
          }
        } else {
          s.at(i) = 'P';
          s.at(i + 1) = 'D';
        }
      }
      if (s.at(i - 1) == 'P')
        s.at(i) = 'D';
      if (s.at(i + 1) == 'D')
        s.at(i) = 'P';
    }
  }
  for (int i = 0; i < len; ++i) {
    if (s.at(i) == '?')
      s.at(i) = 'D';
  }
  //*/
  std::cout << s << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  string T;
  cin >> T;
  if (T.at(0) == '?') {
    T.at(0) = 'D';
  }
  if (T.at(T.size() - 1) == '?') {
    T.at(T.size() - 1) = 'D';
  }
  for (int i = 1; i < T.size() - 1; i++) {
    if (T.at(i) == '?') {
      if ((T.at(i - 1)) == 'P') {
        T.at(i) = 'D';
      }
      if ((T.at(i - 1)) == 'D') {
        if (T.at(i + 1) == 'P') {
          T.at(i) = 'D';
        } else {
          T.at(i) = 'P';
        }
      }
    }
  }
  cout << T << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  string T;
  cin >> T;
  if (T.at(0) == '?') {
    T.at(0) = 'D';
  }
  for (int i = 1; i < T.size(); i++) {
    if (T.at(i) == '?') {
      if ((T.at(i - 1)) == 'P') {
        T.at(i) = 'D';
      }
      if ((T.at(i - 1)) == 'D') {
        if (T.at(i + 1) == 'P') {
          T.at(i) = 'D';
        } else {
          T.at(i) = 'P';
        }
      }
    }
  }
  cout << T << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int find(string str, string word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos;
       pos += word.size()) {
    ++count;
  }
  return count;
}

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.length(); i++)
    if (t[i] == '?')
      t[i] = 'D';
  cout << t << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int find(string str, string word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos;
       pos += word.size()) {
    ++count;
  }
  return count;
}

int main() {
  string t;
  cin >> t;
  int q = count(t.cbegin(), t.cend(), '?');
  rep(i, q) {
    string t1 = t;
    string t2 = t;
    int p = t.rfind("?");
    t1[p] = 'P';
    t2[p] = 'D';
    int totald1 = count(t1.cbegin(), t1.cend(), 'D');
    totald1 += find(t1, "PD");
    int totald2 = count(t2.cbegin(), t2.cend(), 'D');
    totald2 += find(t2, "PD");
    if (totald1 >= totald2) {
      t = t1;
    } else {
      t = t2;
    }
  }
  cout << t << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i, a, b) for (int i = a; i <= b; i++)
#define ALL(a) a.begin(), a.end()
#define ALLN(a, n) (a, a + n)
#define MAX 10000007
#define MIN -10000007

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //  cin>>t;
  while (t--) {
    string s;
    getline(cin, s);
    int n = s.length();
    REP(i, 0, n - 1) {
      if (s.at(i) == '?') {

        s.at(i) = 'D';
      }
    }
    cout << s;
  }
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}


Error: WA

Fixed submission:


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i, a, b) for (int i = a; i <= b; i++)
#define ALL(a) a.begin(), a.end()
#define ALLN(a, n) (a, a + n)
#define MAX 10000007
#define MIN -10000007

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

  int t;
  t = 1;
  //  cin>>t;
  while (t--) {
    string s;
    getline(cin, s);
    int n = s.length();
    REP(i, 0, n - 1) {
      if (s.at(i) == '?') {
        if (i + 1 <= n - 1 && s.at(i - 1) == 'D')
          s.at(i) = 'P';
        else if (i + 1 <= n - 1 && s.at(i - 1) == 'P')
          s.at(i) = 'D';
        else if (i - 1 >= 0 && s.at(i - 1) == 'P')
          s.at(i) = 'D';
        else
          s.at(i) = 'P';
      }
    }
    cout << s;
  }
  cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      t.at(i) = 'D';
    }
  }
  cout << t << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  string t;
  int s = 0;
  cin >> t;
  for (int i = 0; i < t.size() - 2; i++) {
    char c1 = t.at(i);
    char c2 = t.at(i + 1);
    char c3 = t.at(i + 2);
    if (c1 == 'D' && c2 == '?' && c3 == 'D') {
      t.at(i + 1) = 'P';
    }
  }
  for (int i = 0; i < t.size() - 1; i++) {
    char c1 = t.at(i);
    char c2 = t.at(i + 1);
    if (c1 == '?' && c2 == '?') {
      t.at(i) = 'P';
      t.at(i + 1) = 'D';
    }
    if (c1 == 'P' && c2 == '?') {
      t.at(i + 1) = 'D';
    }
  }
  cout << t << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

char a[1 << 20];
int dp[1 << 20][2];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a;
  int n = strlen(a);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] == 'P') {
        dp[i][1] = 0;
      }
      if (a[i] == 'D') {
        dp[i][0] = 1;
      }
      if (a[i] == '?') {
        dp[i][1] = 0;
        dp[i][0] = 1;
      }
      continue;
    }
    if (a[i] == 'P') {
      dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
    }
    if (a[i] == 'D') {
      dp[i][0] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 2);
    }
    if (a[i] == '?') {
      dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
      dp[i][0] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 2);
    }
  }
  int cnt = 0;
  if (dp[n - 1][0] < dp[n - 1][1])
    cnt = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == '?') {
      if (cnt == 0)
        a[i] = 'D';
      else
        a[i] = 'P';
    }
    if (a[i] == 'P') {
      if (dp[i][1] == dp[i - 1][0])
        cnt = 0;
      else
        cnt = 1;
    }
    if (a[i] == 'D') {
      if (dp[i][0] == dp[i - 1][0] + 1)
        cnt = 0;
      else
        cnt = 1;
    }
    if (a[i] == '?') {
      if (cnt == 1) {
        if (dp[i][1] == dp[i - 1][0])
          cnt = 0;
        else
          cnt = 1;
      } else {
        if (dp[i][0] == dp[i - 1][0] + 1)
          cnt = 0;
        else
          cnt = 1;
      }
    }
  }
  cout << a << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <cstdio>

char str[100010];

int main() {
  scanf("%s", str);
  for (int i = 0; str[i]; ++i)
    if (str[i] == '?')
      str[i] = 'D';
  puts(str);
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string T;
  cin >> T;

  for (long long i = 0; i < T.length(); i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }

  cout << T << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string T;
  cin >> T;

  for (long long i = 0; i < 200001; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }

  cout << T << endl;
}