alexjercan/bugnet huggingface dataset:
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;
  string result;

  cin >> str;

  bool found = false;
  int size = str.length();
  for (int i = 0; i < size; ++i) {
    found = false;
    if (str.at(i) == '?') {
      if (i - 1 >= 0) {
        if (str.at(i - 1) == 'P') {
          result += 'D';
          found = true;
        } else if (str.at(i - 1) == '?') {
          if (result.at(i - 1) == 'P') {
            result += 'D';
            found = true;
          }
        }
      }

      if (found)
        continue;

      if (i + 1 < size) {
        if (str.at(i + 1) == 'D') {
          result += 'P';
          found = true;
        } else if (str.at(i + 1) == '?') {
          result += 'P';
          found = true;
        }
      }
      if (!found) {
        result += 'D';
      }
    } else {
      result += str.at(i);
    }
  }
  cout << result;
}

Error: WA

Fixed submission:

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

int main() {
  string str;
  string result;

  cin >> str;

  bool found = false;
  size_t size = str.length();
  for (size_t i = 0; i < size; ++i) {
    found = false;
    if (str.at(i) == '?') {
      if (i - 1 > 0) {
        if (str.at(i - 1) == 'P') {
          result += 'D';
          found = true;
        } else if (str.at(i - 1) == '?') {
          if (result.at(i - 1) == 'P') {
            result += 'D';
            found = true;
          }
        }
      }

      if (found)
        continue;

      if (i + 1 < size) {
        if (str.at(i + 1) == 'D') {
          result += 'P';
          found = true;
        } else if (str.at(i + 1) == '?') {
          result += 'P';
          found = true;
        }
      }
      if (!found) {
        result += 'D';
      }
    } else {
      result += str.at(i);
    }
  }
  cout << result;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  // Your code here!

  string t;
  cin >> t;

  int maxv = -1, cnt = 0;

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

  cout << t << endl;
}


Error: TLE

Fixed submission:

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

int main(void) {
  // Your code here!

  string t;
  cin >> t;

  int maxv = -1, cnt = 0;

  for (int i = 0; i < t.size(); i++)
    if (t[i] == '?')
      cnt++;

  // int idx=0;
  string ans;
  for (int i = 0; i < (1 << cnt); i++) {
    string t1 = t;
    // cout<<t1<<endl;
    int k = 0;
    for (int j = 0; j < t1.size(); j++) {
      if (t1[j] == '?') {
        if ((i >> k) & 1)
          t1[j] = 'P';
        else
          t1[j] = 'D';
        k++;
      }
    }

    int mx = 0;
    for (int j = 0; j < t1.size(); j++) {
      if (t1[j] == 'P') {
        if (t1[j + 1] == 'D')
          mx++;
      } else if (t1[j] == 'D')
        mx++;
    }

    if (mx > maxv) {
      ans = t1;
      maxv = mx;
    }
  }

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

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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

string T;
string ans;
lld maxv = 0;

void solved(string S, lld n, lld v, int before) {
  if (n == T.size()) {
    if (maxv < v) {
      maxv = v;
      ans = S;
    }
    return;
  }
  if (T[n] == 'P') {
    solved(S + "P", n + 1, v, 0);
  } else if (T[n] == 'D') {
    if (before == 0) {
      solved(S + "D", n + 1, v + 2, 1);
    } else {
      solved(S + "D", n + 1, v + 1, 1);
    }
  } else {
    solved(S + "P", n + 1, v, 0);
    if (before == 0) {
      solved(S + "D", n + 1, v + 2, 1);
    } else {
      solved(S + "D", n + 1, v + 1, 1);
    }
  }
}

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

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

Error: TLE

Fixed submission:

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

#define lld long long
#define pi pair<int, int>
#define pl pair<lld, lld>
#define mem0(x) memset(x, 0, sizeof(x))
#define fillnum(x, n) fill(begin(x), end(x), n)
#define asort(x) sort(x.begin(), x.end())
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>())

string T;
string ans;
lld maxv = 0;

void solved(string S, lld n, lld v, int before) {
  if (n == T.size()) {
    if (maxv < v) {
      maxv = v;
      ans = S;
    }
    return;
  }
  if (T[n] == 'P') {
    solved(S + "P", n + 1, v, 0);
  } else if (T[n] == 'D') {
    if (before == 0) {
      solved(S + "D", n + 1, v + 2, 1);
    } else {
      solved(S + "D", n + 1, v + 1, 1);
    }
  } else {
    solved(S + "P", n + 1, v, 0);
    if (before == 0) {
      solved(S + "D", n + 1, v + 2, 1);
    } else {
      solved(S + "D", n + 1, v + 1, 1);
    }
  }
}

int main() {
  cin >> T;
  solved("", 0, 0, -1);
  cout << ans << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

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

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

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

Error: WA

Fixed submission:

#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "ctime"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  string t;
  cin >> t;
  int N = t.size();
  rep(0, i, N) {
    if (t.at(i) == '?') {

      if (i == 0) {
        if (t.at(i + 1) == 'D') {
          t.at(i) = 'P';
        } else {
          t.at(i) = 'D';
        }
      } else if (i == N - 1) {
        t.at(i) = 'D';
      } else if (t.at(i + 1) == 'D') {
        t.at(i) = 'P';
      } else {
        t.at(i) = 'D';
      }
    }
  }
  cout << t << endl;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define INF 1000000000000000000LL
using namespace std;
using ll = long long;

int main() {
  string t;
  cin >> t;
  while (t.find("?") != string::npos)
    t.replace(t.find("?"), 1, "D");

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

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 4)


Fixed submission:

#include <iostream>
#define INF 1000000000000000000LL
using namespace std;
using ll = long long;

int sum = 0;
string ans = "";

int checkDP(string str) {
  int point = 0;
  for (int i = 1; i < str.size() - 1;) {
    string tmp = str.substr(i);
    // cout << "DP: " << tmp << endl;
    if (tmp.find("DP") != string::npos) {
      // cout << t.find("DP") << endl;
      point += 2;
      i = i + 2;
    } else {
      break;
    }
  }

  return point;
}
int checkD(string str) {
  int point = 0;
  for (int i = 1; i < str.size() - 1;) {
    string tmp = str.substr(i);
    // cout << "D: " << tmp << endl;
    if (tmp.find("D") != string::npos) {
      // cout << t.find("D") << endl;
      point += 1;
      i = i + 1;
    } else {
      break;
    }
  }

  return point;
}

void dfs(string done, int points, string yet) {
  if (string::npos == yet.find("?")) {
    // cout << "No ?: " << t << endl;
    string tmp;
    points += checkDP(yet);
    points += checkD(yet);

    if (sum < points) {
      sum = points;
      ans = done + yet;
      // cout << ans << ":" << sum << endl;
    }
  } else {
    // cout << "? was found!" << endl;
    if (yet.find("?") > 2) {
      done = yet;
      done.erase(yet.find("?") - 1);
      yet.erase(0, yet.size() - yet.find("?") - 1);
      cout << "done: " << done << endl;
      cout << "yet: " << yet << endl;
      points += checkDP(done);
      points += checkD(done);
    }
    // cout << "P: " << p << endl;
    dfs(done, points, yet.replace(yet.find("?"), 1, "P"));
    // cout << "D: " << d << endl;
    dfs(done, points, yet.replace(yet.find("?"), 1, "D"));
  }
}

int main() {
  string t;
  cin >> t;
  dfs("", 0, t);

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

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int main() {
  char t[200001];
  scanf("%s", t);
  int len = strlen(t);
  int i;
  for (i = 0; i < len; i++) {
    if (t[i] == '?')
      t[i] = 'D';
  }
  printf("%s\\n", t);
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int main() {
  char t[20001];
  scanf("%s", t);
  int len = strlen(t);
  long long i;
  for (i = 0; i < len; i++) {
    if (t[i] == '?')
      t[i] = 'D';
  }
  printf("%s\\n", t);
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
char s[200010];
int main() {
  for (int i = 0;; i++) {
    scanf("%c", &s[i]);
    if (s[i] == '?') {
      s[i] = 'D';
    } else if (s[i] == '\\0')
      break;
    printf("%c", s[i]);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

char s[N];
int n;

int main() {
  scanf("%s", s);
  n = strlen(s);
  int uk = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'D' || s[i] == '?')
      printf("D");
    else
      printf("P");
  }
  printf("\\n");
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

char s[N];
int n;

int main() {
  scanf("%s", s);
  n = strlen(s);
  int uk = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'D' || s[i] == '?')
      printf("D");
    else
      printf("P");
  }
  printf("\\n");
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM                                                              \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define rep(i, sta, end) for (ll i = sta; i < end; ++i)
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);
// or-> ||
#define DBG(a, b, c, d) // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main() {
  IO_STREAM;
  string T;
  cin >> T;
  if (T[0] == '?') {
    T[0] = 'D';
  }
  reverse(all(T));
  if (T[0] == '?') {
    T[0] = 'D';
  }
  rep(i, 1, T.size() - 1) {
    if (T.at(i) == '?') {
      if (T.at(i - 1) == 'D') {
        if (T.at(i + 1) != 'P') {
          T[i] = 'P';
        } else {
          T[i] = 'D';
        }
      } else {
        T[i] = 'D';
      }
    }
  }
  reverse(all(T));
  cout << T << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM                                                              \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define all(x) x.begin(), x.end()
#define rep(i, sta, end) for (ll i = sta; i < end; ++i)
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);
// or-> ||
#define DBG(a, b, c, d) // cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main() {
  IO_STREAM;
  string T;
  cin >> T;
  reverse(all(T));
  if (T[0] == '?') {
    T[0] = 'D';
  }
  rep(i, 1, T.size()) {
    if (T.at(i) == '?') {
      if (T.at(i - 1) == 'D') {
        if (T.at(i + 1) != 'P') {
          T[i] = 'P';
        } else {
          T[i] = 'D';
        }
      } else {
        T[i] = 'D';
      }
    }
  }
  reverse(all(T));
  cout << T << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

int main() {
  string t;
  cin >> t;
  int p = t.size() - 1;
  if (p == 0) {
    if (t == "?")
      t = 'D';
  }
  if (p != 0) {
    for (int i = 0; i < p; i++) {
      if (t.at(i) == 'P') {
        if (t.at(i + 1) == '?') {
          t.at(i + 1) = 'D';
        }
      }
      if (t.at(i) == '?') {
        if (t.at(i + 1) == 'D')
          t.at(i) = 'P';
        if (t.at(i + 1) == 'P')
          t.at(i) = 'D';
        if (t.at(i + 1) == '?') {
          t.at(i) = 'P';
          t.at(i + 1) = 'D';
        }
      }
      if (t.at(i) == 'D') {
        if (t.at(i + 1) == '?')
          t.at(i + 1) = 'D';
      }
    }
  }

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

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 7) >= this->size() (which is 7)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
using ll = long long;
using namespace std;

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

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

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

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


Error: 0

Fixed submission:

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

int main() {
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++) {
    if (t.at(i) == '?') {
      if (t.at(i + 1) == 'P')
        t.at(i) = 'D';
      else if (t.at(i + 1) == 'D')
        t.at(i) = 'P';
      else {
        t.at(i) = 'P';
        t.at(i + 1) = 'D';
        i++;
      }
    }
  }
  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 uint = unsigned int;

int index(const string &s) {
  int sum = 0;
  rep(i, s.size()) {
    if (s[i] == 'D')
      sum++;
    if (s[i] == 'P' && i < s.size() - 1 && s[i + 1] == 'D')
      sum++;
  }
  return sum;
}

int max_pd = INT_MIN;
string ans = "aho";
void dfs(string &s, int p) {
  if (p == s.size()) {
    int id = index(s);
    if (id > max_pd) {
      ans = string(s);
      max_pd = id;
    }
    return;
  }
  if (s[p] == '?') {
    s[p] = 'P';
    dfs(s, p + 1);
    s[p] = 'D';
    dfs(s, p + 1);
    s[p] = '?';
  } else {
    while (++p < s.size() && s[p] != '?')
      ;
    if (p == s.size()) {
      int id = index(s);
      if (id > max_pd) {
        ans = string(s);
        max_pd = id;
      }
      return;
    }
    dfs(s, p);
  }
}

int main() {
  string s;
  cin >> s;
  for (char &c : s) {
    if (c == '?')
      c = 'D';
  }
  // Bdfs(s, 0);
  cout << s << 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 uint = unsigned int;

int index(const string &s) {
  int sum = 0;
  rep(i, s.size()) {
    if (s[i] == 'D')
      sum++;
    if (s[i] == 'P' && i < s.size() - 1 && s[i + 1] == 'D')
      sum++;
  }
  return sum;
}

int max_pd = INT_MIN;
string ans = "aho";
void dfs(string &s, int p) {
  if (p == s.size()) {
    int id = index(s);
    if (id > max_pd) {
      ans = string(s);
      max_pd = id;
    }
    return;
  }
  if (s[p] == '?') {
    s[p] = 'P';
    dfs(s, p + 1);
    s[p] = 'D';
    dfs(s, p + 1);
    s[p] = '?';
  } else {
    while (++p < s.size() && s[p] != '?')
      ;
    if (p == s.size()) {
      int id = index(s);
      if (id > max_pd) {
        ans = string(s);
        max_pd = id;
      }
      return;
    }
    dfs(s, p);
  }
}

int main() {
  string s;
  cin >> s;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != '?')
      continue;
    if (s[i - 1] == 'P')
      s[i] = 'D';
  }
  dfs(s, 0);
  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 = 1; i < (n); i++)

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

  if (t.size() == 1) {
    if (t.at(0) == '?')
      t.at(0) = 'D';
    cout << t << endl;
    return 0;
  }

  if (t.at(0) == '?') {
    if (t.at(1) == 'D')
      t.at(0) = 'P';
    else
      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';
      else
        t.at(i) = 'D';
    }
  }

  cout << t << endl;
}

Error: WA

Fixed submission:

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

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

  if (t.at(0) == '?') {
    if (t.at(1) == 'D')
      t.at(0) = 'P';
    else
      t.at(0) = 'D';
  }
  rep(i, t.size()) {
    if (t.at(i) == '?') {
      if (t.at(i - 1) == 'P')
        t.at(i) = 'D';
      else
        t.at(i) = 'D';
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
char p[200010];
char a[200010];
int main() {
  int i = 0;
  char ps;
  while (scanf("%c", &ps) != EOF) {
    if (ps == '?') {
      a[i++] = 'D';
    } else
      a[i++] = ps;
  }
  printf("%s", a);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
char p[200010];
char a[200010];
int main() {
  int i;
  scanf("%s", p);
  for (i = 0; i < strlen(p); i++) {
    if (p[i] == '?')
      a[i] = 'D';
    else
      a[i] = p[i];
  }
  printf("%s", a);
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
string t;
string s;
string result;
long long maxn;
void proce() {
  long long num = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'D')
      num++;
    if (s[i] == 'P' && s[i + 1] == 'D')
      num++;
  }
  if (num > maxn) {
    maxn = num;
    result = s;
  }
}
void dfs(int step) {
  if (step > t.size()) {
    proce();
    return;
  }
  if (s[step] == '?') {
    s[step] = 'D';
    dfs(step + 1);
  }
  dfs(step + 1);
}
int main() {
  cin >> t;
  s = t;
  dfs(0);
  cout << result << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string t;

  int flag = 0;

  cin >> t;

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


Error: WA

Fixed submission:

#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) == '?') {
      if (t.at(i - 1) == 'P') {
        t.at(i) = 'D';
      }
      if (t.at(i - 1) == 'D') {
        t.at(i) = 'P';
      }
    }
  }
  cout << t;
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 3000000000000000000; // 10^18
const int inINF = 1000000000;       // 10^9
const ll MOD = 1000000007;          // 10^9+7
const ll MOD2 = 998244353;

int main() {
  string T, ans;

  cin >> T;

  ans = "";
  for (char i : T) {
    if (i == '?') {
      ans += 'D';
    } else {
      ans += i;
    }
  }

  printf("%s\\n", ans.c_str());
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 4294967295) > this->size() (which is 7)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 3000000000000000000; // 10^18
const int inINF = 1000000000;       // 10^9
const ll MOD = 1000000007;          // 10^9+7
const ll MOD2 = 998244353;

string replaceAll(std::string &replacedStr, std::string from, std::string to) {
  unsigned int pos = replacedStr.find(from);
  int toLen = to.length();

  if (from.empty()) {
    return replacedStr;
  }

  while ((pos = replacedStr.find(from, pos)) != std::string::npos) {
    replacedStr.replace(pos, from.length(), to);
    pos += toLen;
  }
  return replacedStr;
}

int main() {
  string T, ans;

  cin >> T;

  replaceAll(T, "?", "D");

  printf("%s\\n", T.c_str());
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() {
  char T[200000];
  cin >> T;
  int i, n = strlen(T);
  for (i = 0; i < n; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
    cout << T[i];
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() {
  char T[20000];
  cin >> T;
  int i, n = strlen(T);
  for (i = 0; i < n; i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
    cout << T[i];
  }
}