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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct _IN {
  _IN() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  template <typename T> operator T() const {
    T x;
    cin >> x;
    return x;
  }
  template <typename Container> void operator()(Container &c) {
    for (auto &x : c)
      cin >> x;
  }
} IN;

const ll MOD = 998244353;
const ll MODI = 499122177;

ll pow2(int e) {
  ll b = 2;
  ll res = 1;
  while (e) {
    if (e & 1)
      (res *= b) %= MOD;
    (b *= b) %= MOD;
    e >>= 1;
  }
  return res;
}

int main() {
  ll N = IN, S = IN;
  vector<int> As(N);
  IN(As);
  vector<ll> dp(S + 1);
  dp[0] = pow2(N);
  for (auto a : As) {
    for (int i = S - a; i >= 0; i--) {
      (dp[i + a] += dp[i] * MODI) %= MOD;
    }
  }
  cout << dp[S] << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

struct _IN {
  _IN() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  template <typename T> operator T() const {
    T x;
    cin >> x;
    return x;
  }
  template <typename Container> void operator()(Container &c) {
    for (auto &x : c)
      cin >> x;
  }
} IN;

const ll MOD = 998244353;
ll pow2(int e) {
  ll b = 2;
  ll res = 1;
  while (e) {
    if (e & 1)
      (res *= b) %= MOD;
    (b *= b) %= MOD;
    e >>= 1;
  }
  return res;
}

int main() {
  ll N = IN, S = IN;
  vector<int> As(N);
  IN(As);
  vector<vector<int>> dp(S + 1);
  dp[0].push_back(0);
  for (auto a : As) {
    for (int i = S - a; i >= 0; i--) {
      for (auto c : dp[i])
        dp[i + a].emplace_back(c + 1);
    }
  }
  ll ans = 0;
  for (int x : dp[S]) {
    (ans += pow2(N - x)) %= MOD;
  }
  cout << ans << endl;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error


/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 3005;
const int mod = 998244353;

int n, s, a[N], p[N], dp[N][N];
ll rec(int i, int x) {
  if (x == 0)
    return p[n - i + 1];
  if (i > n or x < 0)
    return 0;
  int &cache = dp[i][x];
  if (cache != -1)
    return cache;
  return cache = (rec(i + 1, x - a[i]) + 2 * rec(i + 1, x)) % mod;
}
signed main() {
  FastIO;
  p[0] = 1;
  rep(i, 1, 3000) p[i] = p[i - 1] * 2 % mod;
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << rec(1, s);
  return 0;
}


Error: WA

Fixed submission:


/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
 **/

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef double db;
typedef long long ll;

const int N = 3005;
const int mod = 998244353;

int n, s, a[N], p[N], dp[N][N];
ll rec(int i, int x) {
  if (x == 0)
    return p[n - i + 1];
  if (i > n or x < 0)
    return 0;
  int &cache = dp[i][x];
  if (cache != -1)
    return cache;
  return cache = (rec(i + 1, x - a[i]) + 2 * rec(i + 1, x)) % mod;
}
signed main() {
  FastIO;
  p[0] = 1;
  rep(i, 1, 3e5) p[i] = p[i - 1] * 2 % mod;
  cin >> n >> s;
  rep(i, 1, n) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << rec(1, s);
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int mod = 998244353;
long long dp[3001][3001];

int main() {
  int pow[3001];
  pow[0] = 1;
  for (int i = 1; i < 3001; i++) {
    long long p = pow[i - 1];
    p *= 2;
    p %= mod;
    pow[i] = p;
  }

  int N, S;
  cin >> N >> S;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int s = S; s >= 0; s--) {
      int nxt = s + A[i];
      if (dp[i][s] > 0) {
        if (nxt <= S) {
          dp[i + 1][nxt] += dp[i][s];
          dp[i + 1][nxt] %= mod;
        }
        dp[i + 1][s] += dp[i][s] * 2;
        dp[i + 1][s] %= mod;
      }
    }
  }
  cout << dp[N][S] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int mod = 998244353;
long long dp[3001][3001];

int main() {
  int pow[3001];
  pow[0] = 1;
  for (int i = 1; i < 3001; i++) {
    long long p = pow[i - 1];
    p *= 2;
    p %= mod;
    pow[i] = p;
  }

  int N, S;
  cin >> N >> S;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = i; j >= 0; j--) {
      for (int s = S; s >= 0; s--) {
        int nxt = s + A[i];
        if (dp[j][s] > 0 && nxt <= S) {
          dp[j + 1][nxt] += dp[j][s];
          dp[j + 1][nxt] %= mod;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    if (dp[i][S] > 0) {
      long long cur = dp[i][S];
      cur *= pow[N - i];
      cur %= mod;
      ans += cur;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02662 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const ll mod = 998244353;
inline ll read() {
  ll x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}
const int N = 3e3 + 10;
ll dp[N][N];
int a[N], n, s;
void add(ll &x, ll y) { x = (x + y) % mod; }
int main() {
  n = read(), s = read();
  rep(i, 1, n) a[i] = read();
  dp[0][0] = 1;
  rep(i, 1, n) {
    for (int j = 0; j <= s; ++j)
      dp[i][j] = dp[i - 1][j] * 2 % mod;

    for (int j = s; j >= a[i]; --j) {
      add(dp[i][j], dp[i - 1][j - a[i]]);
    }
  }
  printf("%lld\\n", dp[n][s]);
}


Error: -11

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const ll mod = 998244353;
inline ll read() {
  ll x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}
const int N = 1e3 + 10;
ll dp[N][N];
int a[N], n, s;
ll add(ll &x, ll y) { x = (x + y) % mod; }
int main() {
  n = read(), s = read();
  rep(i, 1, n) a[i] = read();
  dp[0][0] = 1;
  rep(i, 1, n) {
    for (int j = 0; j <= s; ++j)
      dp[i][j] = dp[i - 1][j] * 2 % mod;

    for (int j = s; j >= a[i]; --j) {
      add(dp[i][j], dp[i - 1][j - a[i]]);
    }
  }
  printf("%lld\\n", dp[n][s]);
}
Problem p02663 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int H, M, A, B, K;
  cin >> H >> M >> A >> B >> K;
  cout << 60 * (A - H) + B - M - K << endl;
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

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

int main() {
  int H[2], M[2], K;
  cin >> H[1] >> M[1] >> H[2] >> M[2] >> K;
  cout << 60 * (H[2] - H[1]) + M[2] - M[1] - K << endl;
}
Problem p02663 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int H1;
  int M1;
  int H2;
  int M2;
  int K;

  cin >> H1 >> M1 >> H2 >> M2 >> K;

  int wakeUpTime = H1 * 60 + M1;
  int sleepTime = H2 * 60 + M2;
  ;

  int studyTime = sleepTime - wakeUpTime - K;

  printf("%d\\n", studyTime);

  return 0;
}

Error: -11

Fixed submission:


#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  int H1 = atoi(argv[1]);
  int M1 = atoi(argv[2]);
  int H2 = atoi(argv[3]);
  int M2 = atoi(argv[4]);
  int K = atoi(argv[5]);

  int wakeUpTime = H1 * 60 + M1;
  int sleepTime = H2 * 60 + M2;
  ;

  int studyTime = sleepTime - wakeUpTime - K;

  printf("%d\\n", studyTime);

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

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

int main() {
  int t[4];
  for (int i = 0; i < 4; i++)
    cin >> t[i];
  int k;
  cin >> k;

  cout << t[2] * 60 + t[3] - t[0] * 60 - t[1] - k << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int t[4];
  for (int x : t)
    cin >> t[x];
  int k;
  cin >> k;

  cout << t[0] * 60 + t[1] - t[2] * 60 - t[3] - k << endl;
}
Problem p02663 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int h1, m1, h2, m2, k;
  scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
  int n = ((h2 - h1) * 60) + (m2 - m1) - k;
  printf("%d\\n", n);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int h1, m1, h2, m2, k;
  int h = 0, m = 0;
  scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, k);

  h = h2 - h1;
  h *= 60;
  m = m2 - m1;

  printf("%d\\n", h + m - k);

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

#include <iostream>
using namespace std;
int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int diff = (h2 * 60 + m2) - (h1 * 60 + m1);
  // cout<<diff;
  if ((diff - k) > 0)
    cout << diff - k;
  else
    cout << 0;
  return 0;
}

Error: 1

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int diff = (h2 * 60 + m2) - (h1 * 60 + m1);
  // cout<<diff;
  if ((diff - k) > 0)
    cout << diff - k;
  else
    cout << 0;
  return 1;
}
Problem p02663 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

// defines
typedef long long ll;
typedef long double ld;
ll n, m, k, tar, a, b, d, e;
map<ll, ll> ff;

void solve() {
  cin >> n >> m >> a >> b >> k;
  ll ans = abs(((60 * n) + m) - ((60 * a) + b));
  if (k <= ans)
    cout << ans - k;
  else
    cout << 0;
  return;
}

int32_t main() {
#ifdef ONPC
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

// defines
typedef long long ll;
typedef long double ld;
ll n, m, k, tar, a, b, d, e;
map<ll, ll> ff;

ll solve(ll t) {
  cin >> n >> m >> a >> b >> k;
  ll ans = abs(((60 * n) + m) - ((60 * a) + b));
  if (k <= ans)
    cout << ans - k;
  else
    cout << 0;
}

int32_t main() {
#ifdef ONPC
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve(t);
  }

  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h> // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i)  // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r)                                                          \\
  for (int i = (int)(l); i <= (int)(r);                                        \\
       ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n)-1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)   // reverse 1 based

// short hand for usual tokens
#define pb push_back
#define fi first
#define se second

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, aux1, aux2;
  vector<string> possibles;
  cin >> s;
  int n = s.size();
  for0(i, n) {
    if (s[i] == '?') {
      if (i == 0)
        s[i] = 'D';
      else if (i == n - 1)
        s[i] = 'D';
      else {
        if (s[i - 1] == 'P' || s[i + 1] == 'P')
          s[i] = 'D';
        else
          s[i] = 'P';
      }
    }
  }
  cout << s << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h> // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i)  // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r)                                                          \\
  for (int i = (int)(l); i <= (int)(r);                                        \\
       ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n)-1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)   // reverse 1 based

// short hand for usual tokens
#define pb push_back
#define fi first
#define se second

using namespace std;

int q(string s) {
  int n = s.size();
  int x = 0;
  for0(i, n) {
    if (s[i] == 'D')
      x++;
    if (s[i] == 'P' and i < n - 1) {
      if (s[i + 1] == 'D')
        x++;
    }
  }
  return x;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, aux1, aux2;
  vector<string> possibles;
  cin >> s;
  int n = s.size();
  for0(i, n) {
    if (s[i] == '?') {
      aux1 = s;
      aux2 = s;
      aux1[i] = 'D';
      aux2[i] = 'P';
      int x1 = q(aux1), x2 = q(aux2);
      x1 > x2 ? s = aux1 : s = aux2;
    }
  }
  cout << s << endl;
}
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++)
int main(void) {

  string T;

  cin >> T;

  rep(i, T.length()) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }
  cout << T << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(void) {

  char T[100000];

  cin >> T;
  int cnt = 0;

  rep(i, sizeof(T) / sizeof(char)) {
    if (T[i] == '?') {
      T[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 T, Ans;
  cin >> T;
  Ans = "";
  for (int i = 0; i < T.size(); i++) {
    if (T.at(i) == '?') {
      Ans += "D";
    } else {
      Ans += T.at(i);
    }
  }
  cout << Ans << endl;
}

Error: WA

Fixed submission:

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

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

#include <bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x, val) memset(x, val, sizeof x)
#define pb push_back
#define all(v) v.begin(), v.end()
#define unik(v) v.erase(unique(v.begin(), v.end()), v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\\n"
#define debug(a, b)                                                            \\
  cerr << #a << " = " << a << "   |   " << #b << " = " << b << '\\n'
#define endl '\\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 1e5 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  string s, p;
  cin >> s;
  int len = SZ(s);
  for (int i = 0; i < len; i++) {
    if (s[i] == '?')
      s[i] = 'D';
  }
  cout << s << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x, val) memset(x, val, sizeof x)
#define pb push_back
#define all(v) v.begin(), v.end()
#define unik(v) v.erase(unique(v.begin(), v.end()), v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\\n"
#define debug(a, b)                                                            \\
  cerr << #a << " = " << a << "   |   " << #b << " = " << b << '\\n'
#define endl '\\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 1e5 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  string s, p;
  cin >> s;
  int len = SZ(s);
  for (int i = 0; i < len; i++) {
    if (s[i] == '?')
      p[i] = 'D';
    else
      p[i] = s[i];
  }
  int cnt1 = 0;
  for (char ch : p)
    if (ch == 'D')
      cnt1++;

  for (int i = 0; i + 1 < len; i++) {
    if (s[i] == '?' and s[i + 1] == 'D')
      s[i] = 'P';
    else if (s[i] == '?')
      s[i] = 'D';
  }
  if (s.back() == '?') {
    s.back() = 'D';
  }
  int cnt2 = 0;
  for (int i = 0; i + 1 < len; i++) {
    if (s[i] == 'P' and s[i + 1] == 'D')
      cnt2++;
    if (s[i] == 'D')
      cnt2++;
  }
  if (s.back() == 'D')
    cnt2++;

  if (cnt1 > cnt2)
    cout << p << endl;
  else
    cout << s << endl;
  return 0;
}
Problem p02664 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};
ll Nagaemon1;
void swap(ll i, ll j) {
  Nagaemon1 = i;
  i = j;
  j = Nagaemon1;
}
int main() {
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '?')
      s[i] = 'D';
  }
  cout << s << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union {
  vector<ll> par;
  Union(ll a) { par = vector<ll>(a, -1); }
  ll find(ll a) {
    if (par[a] < 0) {
      return a;
    } else {
      return par[a] = find(par[a]);
    }
  }
  bool same(ll a, ll b) { return (find(a) == find(b)); }
  ll size(ll a) { return -par[find(a)]; }
  void unite(ll a, ll b) {
    ll c = find(a), d = find(b);
    if (c == d)
      return;
    if (size(c) < size(d)) {
      swap(c, d);
    }
    par[c] += par[d];
    par[d] = c;
  }
};
ll Nagaemon1;
void swap(ll i, ll j) {
  Nagaemon1 = i;
  i = j;
  j = Nagaemon1;
}
int main() {
  char s[300000];
  cin >> s;
  rep(i, strlen(s)) {
    if (s[i] == '?')
      cout << 'D';
    else
      cout << s[i];
  }
}
Problem p02664 (C++) — buggy submission, verdict: Runtime Error

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

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

  if (t.size() == 1) {
    if (t.at(0) == 'P')
      t.at(0) = 'P';
    else
      t.at(0) = 'D';
  }

  if (t.at(0) == '?' && t.size() > 1) {
    if (t.at(1) == 'P')
      t.at(0) = 'D';
    else
      t.at(0) = 'P';
  }

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

Error: WA

Fixed submission:

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

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

  if (t.at(0) == '?' && t.at(1) == 'P')
    t.at(0) = 'D';
  else
    t.at(0) = 'P';

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

#include <bits/stdc++.h>
#define rep(i, x) for (int i = 0; i < x; i++)
typedef long long ll;
using namespace std;
string T;

void solve() {

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

int main() {
  cin >> T;

  solve();

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, x) for (int i = 0; i < x; i++)
typedef long long ll;
using namespace std;
string T;

ll solve() {

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

int main() {
  cin >> T;

  solve();

  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 s, t, u;
  u = "";
  ll i, j;
  cin >> s;
  j = s.size();
  for (i = 0; i < j; i++) {
    t = s.substr(i, 1);
    if (t == "P") {
      u += "P";
    } else {
      u += "D";
    }
  }
  cout << u;
}

Error: TLE

Fixed submission:

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

int main() {
  string s, t, u, v;
  ll i, j;
  cin >> s;
  j = s.size();
  for (i = j - 1; i >= 0; i--) {
    t = s.substr(i, 1);
    if (t == "?") {
      t = "D";
      u = s.substr(0, i);
      v = s.substr(i + 1);
      s = u + t + v;
    }
  }
  cout << s;
}