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

// atcoder.cpp.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <math.h>
#include <random>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;
// std::random_device rnd;

// グロ変

int main() {
  char enter[200000];
  cin >> enter;

  int t = 0;
  while (1) {
    if (enter[t] == '\\0') {
      break;
    }
    if (enter[t] == '?') {
      enter[t] = 'D';
    }
    t++;
  }

  cout << enter;
}


Error: TLE

Fixed submission:

// atcoder.cpp.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <math.h>
#include <random>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;
// std::random_device rnd;

// グロ変

int main() {
  char enter[10000000];
  cin >> enter;

  int t = 0;
  while (1) {
    if (enter[t] == '\\n') {
      break;
    }
    if (enter[t] == '?') {
      enter[t] = 'D';
    }
  }

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

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

int main() {
  string S;
  cin >> S;

  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '?') {
      S.at(i) = 'D';
    }
  }
  cout << S << endl;
}

Error: WA

Fixed submission:

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

int main() {
  string S;
  cin >> S;

  if (S.at(0) == '?') {
    S.at(0) = 'D';
  }

  for (int i = 0; i < S.size() - 2; i++) {
    if (S.at(i) == 'D' && S.at(i + 1) == '?') {
      S.at(i + 1) = 'D';
    }
    if (S.at(i) == 'P' && S.at(i + 1) == '?') {
      S.at(i + 1) = 'D';
    }
  }

  if (S.at(S.size() - 1) == '?') {
    S.at(S.size() - 1) = 'D';
  }

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

#include <bits/stdc++.h>
using namespace std;
void solve() {
  string str;
  cin >> str;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '?')
      cout << 'D';
    else
      cout << str[i];
  }
}
int main() {
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
void solve() {
  string str;
  cin >> str;
  string s = "";
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '?')
      s = s + 'D';
    else
      s = s + str[i];
  }
  cout << s;
}
int main() {
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

// NOMURA プログラミングコンテストB
#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  cin >> t;

  int n = t.size();
  for (int i = 0; i < n; i++) {
    if (t[i] == '?') {
      t[i] = 'D';
    }
  }

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

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  cin >> t;

  int n = t.size();
  for (int i = 0; i < n; i++) {
    if (t[i] == '?') {
      t.replace(i, i, "D");
    }
  }

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

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

int main() {

  string s;

  cin >> s;
  int len = s.size();
  if (len != 1) {
    if (s.at(0) == '?') {
      if (s.at(1) == 'D') {
        s.at(0) = 'P';
      } else {
        s.at(0) = 'D';
      }
    }
    if (s.at(len - 1) == '?') {
      s.at(len - 1) = 'D';
    }

    for (int i = 1; i <= len - 2; i++) {
      if (s.at(i) == '?') {
        if (s.at(i - 1) == 'P') {
          s.at(i) = 'D';

        } else if (s.at(i + 1) == 'D' || s.at(i + 1) == '?') {
          s.at(i) = 'P';

        } else {

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

Error: WA

Fixed submission:

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

int main() {

  string s;

  cin >> s;
  int len = s.size();
  if (s.at(0) == '?') {
    if (s.at(1) == 'D') {
      s.at(0) = 'P';
    } else {
      s.at(0) = 'D';
    }
  }
  if (s.at(len - 1) == '?') {
    s.at(len - 1) = 'D';
  }

  for (int i = 1; i <= len - 2; i++) {
    if (s.at(i) == '?') {
      if (s.at(i - 1) == 'P') {
        s.at(i) = 'D';

      } else if (s.at(i + 1) == 'D' || s.at(i + 1) == '?') {
        s.at(i) = 'P';

      } else {

        s.at(i) = 'D';
      }
    }
  }
  cout << s;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int n;
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i)
    if (s[i] == '?')
      s[i] = 'D';
  printf("%s\\n", s);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
char s[N];
int n;
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; ++i)
    if (s[i] == '?')
      s[i] = 'D';
  printf("%s\\n", s);
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main() {
  string S;
  cin >> S;
  ll N;

  rep(i, S.size()) {
    if (S.at(i) == '?') {
      S.at(i) = 'D';
    }
  }
  cout << S << endl;
}


Error: WA

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main() {
  string S;
  cin >> S;
  ll N;

  rep(i, S.size()) {
    if (S.at(i) == '?' && S.at(i - 1) == 'P') {
      S.at(i) = 'D';
    } else if (S.at(i) == '?' && S.at(i - 1) == 'D') {
      S.at(i) = 'D';
    } else if (S.at(i) == '?') {
      S.at(i) = 'D';
    }
  }
  cout << S << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
char cc[200010];
int main() {
  scanf("%s", cc);
  int i, j, k, l = strlen(cc);
  for (i = 0; i < l; i++) {
    if (cc[i] == '?') {
      cout << "D";
    } else
      cout << cc[i];
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
char cc[200010];
int main() {
  cin >> cc;
  int i, j, k, l;
  for (i = 0; i < strlen(cc); i++) {
    if (cc[i] == '?') {
      cout << "D";
    } else
      cout << cc[i];
  }
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
string t;
int main() {
  cin >> t;
  if (t.size() == 1) {
    t.at(0) = 'D';
    cout << t << endl;
    return 0;
  }
  if (t.at(0) == '?' && (t.at(1) == '?' || t.at(1) == 'D')) {
    t.at(0) = 'P';
  } else if (t.at(0) == '?' && t.at(1) == 'P') {
    t.at(0) = 'D';
  }
  for (int i = 1; i < t.size() - 1; i++) {
    if (t.at(i - 1) == 'P' && t.at(i) == '?') {
      t.at(i) = 'D';
    } else if (t.at(i - 1) == 'D' && t.at(i) == '?' && t.at(i + 1) != 'P') {
      t.at(i) = 'P';
    } else if (t.at(i - 1) == 'D' && t.at(i) == '?' && t.at(i + 1) == 'P') {
      t.at(i) = 'D';
    }
  }
  if (t.at(t.size() - 1) == '?') {
    t.at(t.size() - 1) = 'D';
  }
  cout << t << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string t;
int main() {
  cin >> t;
  if (t.at(0) == '?' && (t.at(1) == '?' || t.at(1) == 'D')) {
    t.at(0) = 'P';
  } else if (t.at(0) == '?' && t.at(1) == 'P') {
    t.at(0) = 'D';
  }
  for (int i = 1; i < t.size() - 1; i++) {
    if (t.at(i - 1) == 'P' && t.at(i) == '?') {
      t.at(i) = 'D';
    } else if (t.at(i - 1) == 'D' && t.at(i) == '?') {
      t.at(i) = 'P';
    }
  }
  if (t.at(t.size() - 1) == '?') {
    t.at(t.size() - 1) = 'D';
  }
  cout << t << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string t;
  cin >> t;
  for (ll i = 0; i < (ll)t.size(); i++) {
    if (t.at(i) != '?')
      continue;
    if (i == 0) {
      if (i == (ll)t.size() - 1) {
        t.replace(i, 1, "D");
      } else if (t.at(i + 1) == 'P') {
        t.replace(i, 1, "D");
      } else if (t.at(i + 1) == 'D') {
        t.replace(i, 1, "D");
      } else if (t.at(i + 1) == '?') {
        t.replace(i, 1, "P");
      }
    } else {
      if (t.at(i - 1) == 'P') {
        t.replace(i, 1, "D");
      } else if (t.at(i - 1) == 'D') {
        if (i == (ll)t.size() - 1) {
          t.replace(i, 1, "D");
        } else if (t.at(i + 1) == 'P') {
          t.replace(i, 1, "D");
        } else if (t.at(i + 1) == 'D') {
          t.replace(i, 1, "D");
        } else if (t.at(i + 1) == '?') {
          t.replace(i, 1, "P");
        }
      }
    }
  }
  cout << t << endl;
}


Error: WA

Fixed submission:

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

int main() {
  string t;
  cin >> t;
  // long long tl = (long long)t.size();
  for (ll i = 0; i < (ll)t.size(); i++) {
    if (t.at(i) != '?')
      continue;
    else {
      if (t.at(i - 1) == 'P') {
        t.replace(i, 1, "D");
      } else if (t.at(i - 1) == 'D') {
        if (i == (ll)t.size() - 1) {
          t.replace(i, 1, "D");
        } else if (t.at(i + 1) == 'P') {
          t.replace(i, 1, "D");
        } else if (t.at(i + 1) == 'D') {
          t.replace(i, 1, "D");
        } else if (t.at(i + 1) == '?') {
          t.replace(i, 1, "P");
        }
      }
    }
  }
  cout << t << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: WA

Fixed submission:

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

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

#include <iostream>
using namespace std;
int main() {
  char a[200001];
  int i = 0;
  cin >> a;
  for (;;) {
    if (a[i] == '\\0')
      break;
    if (a[i] == '?')
      cout << 'D', i++;
    else
      cout << a[i++];
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  char a[20005];
  int i = 0;
  cin >> a;
  for (;;) {
    if (a[i] == '\\0')
      break;
    if (a[i] == '?') {
      if (a[i - 1] == 'P')
        a[i] = 'D';
      else
        a[i] = 'P';
    }
    cout << a[i++];
  }
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define fornum(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

void mxin(ll &a, ll b) {
  if (a < b)
    a = b;
}

/////////////////////////////////////////////////////
#define INF (ll)1e18

char S[202020];
ll S2[202020], Sn;
ll dp[202020][4];
ll mk[3][3] = {{0, 2}, {0, 1}};
ll i, j, k;
vector<ll> anss;

int main() {
  scanf("%s", S);
  for (Sn = 0; S[Sn]; Sn++)
    ;
  // printf("%lld\\n", Sn);
  fornum(i, 0, Sn) {
    if (S[i] == 'D') {
      S2[i] = 1;
    } else if (S[i] == '?') {
      S2[i] = 2;
    }
  }
  dp[0][0] = INF;
  fornum(i, 0, Sn) {
    if (S2[i] != 1) {
      mxin(dp[i + 1][0], dp[i][0]);
      mxin(dp[i + 1][0], dp[i][1]);
    }
    if (S2[i] != 0) {
      mxin(dp[i + 1][1], dp[i][0] + 2);
      mxin(dp[i + 1][1], dp[i][1] + 1);
    }
    // assert(false);
  }

  ll a = 0, b = 0, c = 0;
  if (dp[Sn][0] > dp[Sn][1]) {
    a = Sn;
    b = 0;
    c = dp[Sn][0];
  } else {
    a = Sn;
    b = 1;
    c = dp[Sn][1];
  }
  // printf("%lld\\n", c);
  while (a > 0) {
    anss.push_back(b);
    --a;
    if (dp[a][0] + mk[0][b] == c) {
      b = 0;
      c = dp[a][0];
    } else {
      b = 1;
      c = dp[a][1];
    }
    assert(b == 1 || b == 0);
  }
  i = Sn - 1;
  while (i >= 0) {
    if (anss[i] == 0) {
      printf("P");
    } else {
      printf("D");
    }
    --i;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define fornum(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

ll mxin(ll &a, ll b) {
  if (a < b)
    a = b;
}

/////////////////////////////////////////////////////
#define INF (ll)1e18

char S[202020];
ll S2[202020], Sn;
ll dp[202020][4];
ll mk[3][3] = {{0, 2}, {0, 1}};
ll i, j, k;
vector<ll> anss;

int main() {
  scanf("%s", S);
  Sn = strlen(S);
  fornum(i, 0, Sn) {
    if (S[i] == 'D') {
      S2[i] = 1;
    } else if (S[i] == '?') {
      S2[i] = 2;
    }
  }
  dp[0][0] = INF;
  fornum(i, 0, Sn) {
    if (S2[i] != 1) {
      mxin(dp[i + 1][0], dp[i][0]);
      mxin(dp[i + 1][0], dp[i][1]);
    }
    if (S2[i] != 0) {
      mxin(dp[i + 1][1], dp[i][0] + 2);
      mxin(dp[i + 1][1], dp[i][1] + 1);
    }
  }
  ll a, b, c;
  if (dp[Sn][0] > dp[Sn][1]) {
    a = Sn;
    b = 0;
    c = dp[Sn][0];
  } else {
    a = Sn;
    b = 1;
    c = dp[Sn][1];
  }
  // printf("%lld\\n", c);
  while (a > 0) {
    anss.push_back(b);
    --a;
    if (dp[a][0] + mk[0][b] == c) {
      b = 0;
      c = dp[a][0];
    } else {
      b = 1;
      c = dp[a][1];
    }
  }
  i = Sn - 1;
  while (i >= 0) {
    if (anss[i] == 0) {
      printf("P");
    } else {
      printf("D");
    }
    --i;
  }
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string T;
  cin >> T;
  ll count = 0;

  for (ll i = 0; i < (int)T.size(); i++) {
    if (T.at(i) == '?') {
      T.at(i) = 'D';
    }
  }

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

Error: TLE

Fixed submission:

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

int main() {
  string T;
  cin >> T;
  ll count = 0;

  for (ll i = 0; i < (int)T.size(); i++) {
    if (i != (int)T.size() - 1 && T.at(i) == '?' && T.at(i + 1) == '?') {
      count++;
    }
  }

  for (ll j = 0; j < count + 2; j++) {

    for (ll i = 0; i < (int)T.size(); i++) {
      if (i == (int)T.size() - 1 && T.at(i) == '?') {
        T.at(i) = 'D';
      } else if (i != (int)T.size() - 1 && T.at(i) == '?' &&
                 T.at(i + 1) == 'P') {
        T.at(i) = 'D';
      } else if (i != (int)T.size() - 1 && T.at(i) == '?' &&
                 T.at(i + 1) == 'D') {
        T.at(i) = 'P';
      }
    }
  }

  for (ll i = 0; i < (int)T.size(); i++) {
    cout << T.at(i);
  }
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string T;
  cin >> T;
  int size;
  size = T.size();

  if (size == 1) {
    if (T.at(0) == '?') {
      T.at(0) = 'D';
    }
  } else if (size != 1) {
    for (int i = 0; i < size; i++) {
      if (T.at(i) == '?') {
        T.at(i) = 'D';
      }
    }
  }
  cout << T << endl;
}


Error: WA

Fixed submission:

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

int main() {
  string T;
  cin >> T;
  int size;
  size = T.size();

  if (T.at(0) == '?') {
    if (T.at(1) == 'P') {
      T.at(0) = 'D';
    }
    if (T.at(1) == 'D') {
      T.at(0) = 'D';
    }
    if (T.at(0) == '?') {
      T.at(0) = 'D';
    }
  }
  for (int i = 1; i < size - 1; i++) {
    if (T.at(i) == '?') {
      if (T.at(i - 1) == 'P' && T.at(i + 1) == 'P') {
        T.at(i) = 'D';
      }
      if (T.at(i - 1) == 'P' && T.at(i + 1) == 'D') {
        T.at(i) = 'P';
      }
      if (T.at(i - 1) == 'D' && T.at(i + 1) == 'P') {
        T.at(i) = 'D';
      }
      if (T.at(i - 1) == 'D' && T.at(i + 1) == 'D') {
        T.at(i) = 'P';
      }
      if (T.at(i - 1) == 'P' && T.at(i + 1) == '?') {
        T.at(i) = 'D';
      }
      if (T.at(i - 1) == 'D' && T.at(i + 1) == '?') {
        T.at(i) = 'D';
      }
    } else {
      continue;
    }
  }
  if (T.at(size - 1) == '?') {
    T.at(size - 1) = 'D';
  }
  cout << T << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

const int M = 2e5 + 100;
int main() {
  char s[M];
  while (scanf("%s", s) == 1) {
    int n = strlen(s);
    for (int i = 0; i < n; i++)
      if (s[i] == '?')
        s[i] = 'D';
    printf("%s\\n", s);
  }
}


Error: WA

Fixed submission:

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

const int M = 1e5 + 100;
int main() {
  char s[M];
  while (scanf("%s", s) == 1) {
    int n = strlen(s);
    for (int i = 0; i < n; i++)
      if (s[i] == '?')
        s[i] = 'D';
    printf("%s\\n", s);
  }
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

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

  for (int i = 0; i < t.size(); i++) {
    cout << t[i] << "";
  }
  cout << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

void printString(string &t, int size) {
  for (int i = 0; i < size; i++) {
    cout << t[i] << "";
  }
  cout << endl;
}

int cntVector(string &t, long long t_size) {
  long long cnt = 0;
  for (int i = 0; i < t_size; i++) {
    if (i > 0 && t[i - 1] == 'P' && t[i] == '?') {
      t[i] = 'D';
      cnt++;
    }
    if (i > 0 && t[i - 1] == 'D' && t[i] == '?') {
      if (i + 1 == 'D' || i + 1 == '?') {
        t[i] = 'P';
      } else {
        t[i] = 'D';
        cnt++;
      }
      // (t[i + 1] == 'D') t[i] = 'P';
    }
    if (t[i] == 'D')
      cnt++;
  }
  return cnt;
}

int main() {
  string t, t1, t2;
  cin >> t;
  long long ma = 0;
  for (int i = 0; i < t.size(); i++) {
    t1[i] = t[i];
    t2[i] = t[i];
  }

  if (t[0] == '?') {
    t1[0] = 'P';
    t2[0] = 'D';
  }

  long long t_cnt = cntVector(t, t.size());
  long long t1_cnt = cntVector(t1, t.size());
  long long t2_cnt = cntVector(t2, t.size());

  ma = max(ma, t_cnt);
  ma = max(ma, t1_cnt);
  ma = max(ma, t2_cnt);

  if (t_cnt == ma)
    printString(t, t.size());
  else if (t1_cnt == ma)
    printString(t1, t.size());
  else
    printString(t2, t.size());

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

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

int main() {

  string s;
  cin >> s;
  string output = "";

  if (s.length() == 1)
    if (s.at(0) == '?')
      cout << "D";
    else
      cout << s.at(0);
  else {
    for (int i = 0; i < s.length(); i++) {
      if (s.at(i) == '?') {
        if (i == 0 && s.at(i + 1) == 'D')
          output += 'P';
        else
          output += 'D';
        continue;
      }
      output += s.at(i);
    }
    cout << output;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {

  string s;
  cin >> s;
  string output = "";

  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == '?') {
      if (i == 0 && s.at(i + 1) == 'D')
        output += 'P';
      else
        output += 'D';
      continue;
    }
    output += s.at(i);
  }
  cout << output;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
using namespace std;
char ch[200005];
int main() {
  scanf("%s", ch);
  int len = strlen(ch);
  for (int i = 0; i < len; ++i) {
    if (ch[i] == '?') {
      ch[i] = 'D';
    }
  }
  printf("%s\\n", ch);
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;
char ch[2000005];
int main() {
  scanf("%s", ch);
  for (int i = 0; i < strlen(ch); ++i) {
    if (ch[i] == '?') {
      ch[i] = 'D';
    }
  }
  printf("%s\\n", ch);
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 200020
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
char s[N];
int n;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    putchar(s[i] == 'P' ? 'P' : 'D');
  }
  return 0;
}


Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define N 233
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return x * f;
}
char s[N];
int n;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    putchar(s[i] == 'P' ? 'P' : 'D');
  }
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  string T;
  cin >> T;

  bool pre_P = false;
  bool flag = false;
  ll count = 0;
  for (int i = 0; i < T.size(); i++) {
    if (T.at(i) == 'P') {
      pre_P = true;
      if (flag == true) {
        T.at(i - 1) = 'D';
        count++;
        flag = false;
      }
    } else if (T.at(i) == 'D') {
      count++;
      if (pre_P == true)
        count++;
      pre_P = false;
      if (flag == true) {
        T.at(i - 1) = 'P';
        count++;
        flag = false;
      }
    } else if (T.at(i) == '?') {
      if (flag == true) {
        T.at(i - 1) = 'P';
        T.at(i) = 'D';
        count += 2;
        pre_P = false;
        flag = false;
        continue;
      }
      if (pre_P == true) {
        T.at(i) = 'D';
        count += 2;
        pre_P = false;
      } else {
        if (i == T.size() - 1) {
          T.at(i) = 'D';
          count++;
          continue;
        }
        flag = true;
      }
      pre_P = false;
    }
  }

  cout << T << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  string T;
  cin >> T;

  bool pre_P = false;
  bool flag = false;
  ll count = 0;
  for (int i = 0; i < T.size(); i++) {
    if (T.at(i) == 'P') {
      pre_P = true;
      if (flag == true) {
        T.at(i - 1) = 'D';
        count++;
        flag = false;
      }
    } else if (T.at(i) == 'D') {
      count++;
      if (pre_P == true)
        count++;
      pre_P = false;
      if (flag = true) {
        T.at(i - 1) = 'P';
        count++;
        flag = false;
      }
    } else if (T.at(i) == '?') {
      if (flag == true) {
        T.at(i - 1) = 'P';
        T.at(i) = 'D';
        count += 2;
        pre_P = false;
        flag = false;
        continue;
      }
      if (pre_P = true) {
        T.at(i) = 'D';
        count += 2;
        pre_P = false;
      } else {
        if (i == T.size() - 1) {
          T.at(i) = 'D';
          count++;
          continue;
        }
        flag = true;
      }
      pre_P = false;
    }
  }

  cout << T << endl;

  return 0;
}