prithivMLmods/Coder-Stat huggingface dataset:
Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int h, w;
char s[2001][2001];
int result[2001][2001][4] = {};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int getresult(int i, int j, int k) {
  if (i < 0 || j < 0 || i >= h || j >= w)
    return 0;
  if (result[i][j][k] >= 0)
    return result[i][j][k];
  if (s[i][j] == '#')
    return result[i][j][k] = 0;
  return getresult(i + dx[k], j + dy[k], k) + 1;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      for (int k = 0; k < 4; k++) {
        result[i][j][k] = -1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      int nowresult = 0;
      for (int k = 0; k < 4; k++) {
        nowresult += getresult(i + dx[k], j + dy[k], k);
      }
      nowresult++;
      ans = max(ans, nowresult);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int h, w;
char s[2001][2001];
int result[2001][2001][4] = {};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int getresult(int i, int j, int k) {
  if (i < 0 || j < 0 || i >= h || j >= w)
    return 0;
  if (result[i][j][k] >= 0)
    return result[i][j][k];
  if (s[i][j] == '#')
    return result[i][j][k] = 0;
  return result[i][j][k] = getresult(i + dx[k], j + dy[k], k) + 1;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      for (int k = 0; k < 4; k++) {
        result[i][j][k] = -1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      int nowresult = 0;
      for (int k = 0; k < 4; k++) {
        nowresult += getresult(i + dx[k], j + dy[k], k);
      }
      nowresult++;
      ans = max(ans, nowresult);
    }
  }
  cout << ans << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> s(h);

  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> cnt(h, vector<int>(w));

  for (int i = 0; i < h; i++) {
    vector<int> done(w);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + 1 < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  for (int j = 0; j < w; j++) {
    vector<int> done(h);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt[i][j] - 1);
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> s(h);

  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> cnt(h, vector<int>(w));

  for (int i = 0; i < h; i++) {
    vector<int> done(w);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }

  for (int j = 0; j < w; j++) {
    vector<int> done(h);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt[i][j] - 1);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int H, W;
char M[2005][2005];

bool vis[4][2005][2005];

int D[4][2005][2005];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

inline bool val(int i, int j) { return 0 <= i && i < H && 0 <= j && j < W; }

int dfs(int k, int i, int j) {
  if (vis[k][i][j])
    return D[k][i][j];
  if (M[i][j] == '#')
    return 0;
  if (!val(i, j))
    return 0;
  int x = i + dx[k], y = j + dy[k];
  return D[k][i][j] = dfs(k, x, y) + 1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> M[i];
  }
  for (int k = 0; k < 4; k++) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (vis[k][i][j])
          continue;
        dfs(k, i, j);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, D[0][i][j] + D[1][i][j] + D[2][i][j] + D[3][i][j] - 3);
    }
  }
  cout << ans << endl;
}


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

int H, W;
char M[2005][2005];

bool vis[4][2005][2005];

int D[4][2005][2005];

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

inline bool val(int i, int j) { return 0 <= i && i < H && 0 <= j && j < W; }

int dfs(int k, int i, int j) {
  if (vis[k][i][j])
    return D[k][i][j];
  if (M[i][j] == '#')
    return 0;
  if (!val(i, j))
    return 0;
  vis[k][i][j] = true;
  int x = i + dx[k], y = j + dy[k];
  return D[k][i][j] = dfs(k, x, y) + 1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> M[i];
  }
  for (int k = 0; k < 4; k++) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (vis[k][i][j])
          continue;
        dfs(k, i, j);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans = max(ans, D[0][i][j] + D[1][i][j] + D[2][i][j] + D[3][i][j] - 3);
    }
  }
  cout << ans << endl;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

const int MOD = 1e9 + 7;

void solve(void) {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < h; i++) {
    cin >> g[i];
  }
  vector<vector<int>> hs(w, vector<int>(h)), ws(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j == 0) {
        ws[i][j] = g[i][j] == '.';
      } else {
        if (g[i][j] == '.') {
          ws[i][j] = ws[i][j - 1] + 1;
        }
      }
    }
    for (int j = w - 1; j > 0; j--) {
      if (ws[i][j - 1] == 0 || ws[i][j] == 0) {
        continue;
      }
      ws[i][j - 1] = ws[i][j];
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = 0; i < h; i++) {
      if (i == 0) {
        hs[i][j] = g[i][j] == '.';
      } else {
        if (g[i][j] == '.') {
          hs[i][j] = hs[i - 1][j] + 1;
        }
      }
    }
    for (int i = h - 1; i > 0; i--) {
      if (hs[i - 1][j] == 0 || hs[i][j] == 0) {
        continue;
      }
      hs[i - 1][j] = hs[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '.') {
        ans = max(ans, hs[i][j] + ws[i][j] - 1);
      }
    }
  cout << ans << endl;
}

int main() {
  solve();
  // cout << "yui(*-v・)yui" << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

const int MOD = 1e9 + 7;

void solve(void) {
  int h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < h; i++) {
    cin >> g[i];
  }
  vector<vector<int>> hs(2020, vector<int>(2020)), ws(2020, vector<int>(2020));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j == 0) {
        ws[i][j] = g[i][j] == '.';
      } else {
        if (g[i][j] == '.') {
          ws[i][j] = ws[i][j - 1] + 1;
        }
      }
    }
    for (int j = w - 1; j > 0; j--) {
      if (ws[i][j - 1] == 0 || ws[i][j] == 0) {
        continue;
      }
      ws[i][j - 1] = ws[i][j];
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = 0; i < h; i++) {
      if (i == 0) {
        hs[i][j] = g[i][j] == '.';
      } else {
        if (g[i][j] == '.') {
          hs[i][j] = hs[i - 1][j] + 1;
        }
      }
    }
    for (int i = h - 1; i > 0; i--) {
      if (hs[i - 1][j] == 0 || hs[i][j] == 0) {
        continue;
      }
      hs[i - 1][j] = hs[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '.') {
        ans = max(ans, hs[i][j] + ws[i][j] - 1);
      }
    }
  cout << ans << endl;
}

int main() {
  solve();
  // cout << "yui(*-v・)yui" << endl;
  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  bool field[h + 1][w + 1];
  for (int i = 1; i <= h; i++) {
    char c;
    for (int j = 1; j <= w; j++) {
      cin >> c;
      if (c == '#') {
        field[i][j] = false;
      } else {
        field[i][j] = true;
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int tmp = 0;
      if (field[i][j]) {
        // up
        for (int k = i + 1; k <= h; k++) {
          if (!field[k][j]) {
            break;
          } else {
            tmp++;
          }
        }
        // down
        for (int k = i - 1; k >= 1; k--) {
          if (!field[k][j]) {
            break;
          } else {
            tmp++;
          }
        }
        // right
        for (int k = j + 1; k <= w; k++) {
          if (!field[i][k]) {
            break;
          } else {
            tmp++;
          }
        }
        // down
        for (int k = j - 1; k >= 1; k--) {
          if (!field[i][k]) {
            break;
          } else {
            tmp++;
          }
        }
        ans = max(ans, tmp + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  bool field[h + 1][w + 1];
  for (int i = 1; i <= h; i++) {
    char c;
    for (int j = 1; j <= w; j++) {
      cin >> c;
      if (c == '#') {
        field[i][j] = false;
      } else {
        field[i][j] = true;
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int tmp = 0;
      if (field[i][j]) {
        // up
        for (int k = i + 1; k <= h; k++) {
          if (!field[k][j]) {
            break;
          } else {
            tmp++;
          }
        }
        // down
        for (int k = i - 1; k >= 1; k--) {
          if (!field[k][j]) {
            break;
          } else {
            tmp++;
          }
        }
        // right
        for (int k = j + 1; k <= w; k++) {
          if (!field[i][k]) {
            break;
          } else {
            tmp++;
          }
        }
        // down
        for (int k = j - 1; k >= 1; k--) {
          if (!field[i][k]) {
            break;
          } else {
            tmp++;
          }
        }
        ans = max(ans, tmp + 1);
      }
      if (ans == h + w - 1) {
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

bool m[2010][2010];
int *l1[2010][2010];
int *l2[2010][2010];
int ll1[2000000];
int ll2[2000000];

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      m[i][j] = (s[j] == '#');
    }
  }
  int ll1p = 0;
  int ll2p = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (m[i][j]) {
        l1[i][j] = NULL;
        ll1p++;
      } else {
        l1[i][j] = &ll1[ll1p];
        ll1[ll1p]++;
      }
    }
    ll1p++;
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (m[j][i]) {
        l2[j][i] = NULL;
        ll2p++;
      } else {
        l2[j][i] = &ll2[ll2p];
        ll2[ll2p]++;
      }
    }
    ll2p++;
  }
  //    for(int i = 0; i < h; i++){
  //        for(int j = 0; j < w; j++){
  //            if(l2[i][j] == NULL){
  //                cerr << 0;
  //            }else{
  //                cerr << *l2[i][j];
  //            }
  //        }
  //        cerr << endl;
  //    }

  int ma = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (l1[i][j] == NULL || l2[i][j] == NULL) {
        continue;
      }
      int c = *l1[i][j] + *l2[i][j] - 1;
      ma = max(ma, c);
    }
  }

  cout << ma << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

bool m[2010][2010];
int *l1[2010][2010];
int *l2[2010][2010];
int ll1[4000000];
int ll2[4000000];

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      m[i][j] = (s[j] == '#');
    }
  }
  int ll1p = 0;
  int ll2p = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (m[i][j]) {
        l1[i][j] = NULL;
        ll1p++;
      } else {
        l1[i][j] = &ll1[ll1p];
        ll1[ll1p]++;
      }
    }
    ll1p++;
  }
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (m[j][i]) {
        l2[j][i] = NULL;
        ll2p++;
      } else {
        l2[j][i] = &ll2[ll2p];
        ll2[ll2p]++;
      }
    }
    ll2p++;
  }
  //    for(int i = 0; i < h; i++){
  //        for(int j = 0; j < w; j++){
  //            if(l2[i][j] == NULL){
  //                cerr << 0;
  //            }else{
  //                cerr << *l2[i][j];
  //            }
  //        }
  //        cerr << endl;
  //    }

  int ma = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (l1[i][j] == NULL || l2[i][j] == NULL) {
        continue;
      }
      int c = *l1[i][j] + *l2[i][j] - 1;
      ma = max(ma, c);
    }
  }

  cout << ma << endl;

  return 0;
}
Problem p03016 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

typedef vector<ll> vec;
typedef vector<vec> mat;

ll L, A, B, MOD;

mat mul(mat &a, mat &b) {
  mat c(a.size(), vec(b[0].size()));
  rep(i, a.size()) rep(j, b[0].size())
      rep(k, b.size())(c[i][j] += a[i][k] * b[k][j]) %= MOD;
  return c;
}
mat ppow(mat &a, ll b) {
  mat res(a.size(), vec(a.size()));
  rep(i, a.size()) res[i][i] = 1;
  while (b) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

ll ppow(ll a, ll b) {
  a %= MOD;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

ll lb(ll x) {
  ll ok = L, ng = -1;
  while (ok - ng > 1) {
    ll t = (ok + ng) / 2;
    if (A + B * t >= x)
      ok = t;
    else
      ng = t;
  }
  return ok;
}

int main() {
  cin >> L >> A >> B >> MOD;
  ll d = 1;
  ll ans = 0;
  for (ll i = 1; i <= 18; i++) {
    ll l = lb(d), r = lb(d * 10);
    (ans *= ppow(10, i * (r - l))) %= MOD;
    ll s = (A + B % MOD * l) % MOD;
    mat M1{{d * 10 % MOD, 1, 0}, {0, 1, 1}, {0, 0, 1}};
    mat M2{{0}, {s}, {B % MOD}};
    mat res = ppow(M1, r - l);
    M2 = mul(res, M2);
    (ans += M2[0][0]) %= MOD;
    d *= 10;
  }
  cout << ans << endl;
}

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

typedef vector<ll> vec;
typedef vector<vec> mat;

ll L, A, B, MOD;

mat mul(mat &a, mat &b) {
  mat c(a.size(), vec(b[0].size()));
  rep(i, a.size()) rep(j, b[0].size())
      rep(k, b.size())(c[i][j] += a[i][k] * b[k][j]) %= MOD;
  return c;
}
mat ppow(mat &a, ll b) {
  mat res(a.size(), vec(a.size()));
  rep(i, a.size()) res[i][i] = 1;
  while (b) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

ll ppow(ll a, ll b) {
  a %= MOD;
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}

ll lb(ll x) {
  ll ok = L, ng = -1;
  while (ok - ng > 1) {
    ll t = (ok + ng) / 2;
    if (A + B * t >= x)
      ok = t;
    else
      ng = t;
  }
  return ok;
}

int main() {
  cin >> L >> A >> B >> MOD;
  ll d = 1;
  ll ans = 0;
  for (ll i = 1; i <= 18; i++) {
    ll l = lb(d), r = lb(d * 10);
    (ans *= ppow(d * 10, (r - l))) %= MOD;
    ll s = (A + B % MOD * l) % MOD;
    mat M1{{d * 10 % MOD, 1, 0}, {0, 1, 1}, {0, 0, 1}};
    mat M2{{0}, {s}, {B % MOD}};
    mat res = ppow(M1, r - l);
    M2 = mul(res, M2);
    (ans += M2[0][0]) %= MOD;
    d *= 10;
  }
  cout << ans << endl;
}
Problem p03017 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  bool ans = true;
  s[n] = '#';
  for (ll i = b; i <= d; i++) {
    if (s[i] == '#' && s[i + 1] == '#') {
      ans = false;
      break;
    }
    for (ll i = a; i <= c; i++) {
      if (s[i] == '#' && s[i + 1] == '#') {
        ans = false;
        break;
      }
    }
  }
  if (c > d) {
    ans = false;
    for (ll i = b; i <= d; i++) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
        ans = true;
      }
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;
  bool ans = true;
  s[n] = '#';
  for (ll i = b; i <= d; i++) {
    if (s[i] == '#' && s[i + 1] == '#') {
      ans = false;
      break;
    }
  }
  for (ll i = a; i <= c; i++) {
    if (s[i] == '#' && s[i + 1] == '#') {
      ans = false;
      break;
    }
  }
  if (c > d) {
    ans = false;
    for (ll i = b; i <= d; i++) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
        ans = true;
      }
    }
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

const int MAXN = 100000;

char s[1 + MAXN];
bool dpa[1 + MAXN], dpb[1 + MAXN], dpc[1 + MAXN], dpd[1 + MAXN];

void dodp(int n, int x, bool *dp) {
  dp[x] = true;
  for (int i = x + 1; i <= n; i++)
    dp[i] = (s[i] != '#') && (dp[i - 1] || dp[i - 2]);
  for (int i = x - 1; i >= 1; i--)
    dp[i] = (s[i] != '#') && (dp[i + 1] || dp[i + 2]);
}

void print(bool answer) {
  if (answer)
    cout << "Yes\n";
  else
    cout << "No\n";
}

int main() {
  // ifstream cin("input.in");
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d >> (s + 1);
  dodp(n, a, dpa);
  dodp(n, b, dpb);
  dodp(n, c, dpc);
  dodp(n, d, dpd);
  if (c < d)
    print(dpa[c] && dpb[d]);
  else {
    for (int i = b; i <= d; i++)
      if (dpb[i] && dpd[i] && dpa[i - 1] && dpc[i + 1]) {
        print(true);
        return 0;
      }
    print(false);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

const int MAXN = 200000;

char s[1 + MAXN];
bool dpa[1 + MAXN], dpb[1 + MAXN], dpc[1 + MAXN], dpd[1 + MAXN];

void dodp(int n, int x, bool *dp) {
  dp[x] = true;
  for (int i = x + 1; i <= n; i++)
    dp[i] = (s[i] != '#') && (dp[i - 1] || dp[i - 2]);
  for (int i = x - 1; i >= 1; i--)
    dp[i] = (s[i] != '#') && (dp[i + 1] || dp[i + 2]);
}

void print(bool answer) {
  if (answer)
    cout << "Yes\n";
  else
    cout << "No\n";
}

int main() {
  // ifstream cin("input.in");
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d >> (s + 1);
  dodp(n, a, dpa);
  dodp(n, b, dpb);
  dodp(n, c, dpc);
  dodp(n, d, dpd);
  if (c < d)
    print(dpa[c] && dpb[d]);
  else {
    for (int i = b; i <= d; i++)
      if (dpb[i] && dpd[i] && dpa[i - 1] && dpc[i + 1]) {
        print(true);
        return 0;
      }
    print(false);
  }
  return 0;
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  string s, res;
  cin >> s;

  ll m = max(c, d);

  int x = 0;
  for (ll i = a; i < m; i++) {
    if (s.at(i) == '#' && x) {
      res = "No";
      cout << res << endl;
      return 0;
    }

    if (s.at(i) == '#') {
      x = 1;
    } else {
      x = 0;
    }
  }

  if (c < d) {
    res = "Yes";
    cout << res << endl;
  }

  else {
    for (ll i = b - 2; i < d; i++) {
      if (s.at(i) == '.' && s.at(i + 1) == '.' && s.at(i + 2) == '.') {
        res = "Yes";
        cout << res << endl;
        return 0;
      }
    }

    res = "No";
    cout << res << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  string s, res;
  cin >> s;

  ll m = max(c, d);

  int x = 0;
  for (ll i = a; i < m; i++) {
    if (s.at(i) == '#' && x) {
      res = "No";
      cout << res << endl;
      return 0;
    }

    if (s.at(i) == '#') {
      x = 1;
    } else {
      x = 0;
    }
  }

  if (c < d) {
    res = "Yes";
    cout << res << endl;
  }

  else {
    for (ll i = b - 1; i < d; i++) {
      if (s.at(i - 1) == '.' && s.at(i) == '.' && s.at(i + 1) == '.') {
        res = "Yes";
        cout << res << endl;
        return 0;
      }
    }

    res = "No";
    cout << res << endl;
  }

  return 0;
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define range(a) a.begin(), a.end()
int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  if (C < D) {
    bool flag = true;
    rep(i, A - 1, C - 2) {
      if (S.at(i) == '#' && S.at(i + 1) == '#') {
        flag = false;
        break;
      }
    }
    rep(i, B - 1, D - 2) {
      if (S.at(i) == '#' && S.at(i + 1) == '#') {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    bool flag1 = true;
    rep(i, A - 1, C - 2) {
      if (S.at(i) == '#' && S.at(i + 1) == '#') {
        flag1 = false;
        break;
      }
    }
    bool flag2 = false;
    int a, b, c;
    a = S.at(B - 2);
    b = S.at(B - 1);
    c = S.at(B);
    rep(i, B - 2, D - 1) {
      if (a == '.' && b == '.' && c == '.') {
        flag2 = true;
        break;
      }
      a = b;
      b = c;
      c = S.at(i + 3);
    }
    if (flag1 == true && flag2 == true) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define range(a) a.begin(), a.end()
int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  string S;
  cin >> S;
  if (C < D) {
    bool flag = true;
    rep(i, A - 1, C - 2) {
      if (S.at(i) == '#' && S.at(i + 1) == '#') {
        flag = false;
        break;
      }
    }
    rep(i, B - 1, D - 2) {
      if (S.at(i) == '#' && S.at(i + 1) == '#') {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    bool flag1 = true;
    rep(i, A - 1, C - 2) {
      if (S.at(i) == '#' && S.at(i + 1) == '#') {
        flag1 = false;
        break;
      }
    }
    bool flag2 = false;
    int a, b, c;
    a = S.at(B - 2);
    b = S.at(B - 1);
    c = S.at(B);
    rep(i, B - 2, D - 1) {
      if (a == '.' && b == '.' && c == '.') {
        flag2 = true;
        break;
      }
      a = b;
      b = c;
      if (i != D - 2)
        c = S.at(i + 3);
    }
    if (flag1 == true && flag2 == true) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> n >> s;
  s = " " + s;
  auto check = [&](int l, int r) {
    if (s[l] == '#' || s[r] == '#')
      return false;
    for (int i = l + 1; i <= r; i++) {
      if (s[i] == '#' && s[i - 1] == '#')
        return false;
    }
    return true;
  };
  if (c == d)
    return puts("No"), 0;
  if (c < d) {
    if (check(b, d) && check(a, c))
      puts("Yes");
    else
      puts("No");
    return 0;
  } else {
    if (!check(b, d) || !check(a, c))
      return puts("No"), 0;
    for (int i = b; i <= d; i++) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.')
        return puts("Yes"), 0;
      // puts("N");
    }
    puts("No");
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  s = " " + s;
  auto check = [&](int l, int r) {
    if (s[l] == '#' || s[r] == '#')
      return false;
    for (int i = l + 1; i <= r; i++) {
      if (s[i] == '#' && s[i - 1] == '#')
        return false;
    }
    return true;
  };
  if (c == d)
    return puts("No"), 0;
  if (c < d) {
    if (check(b, d) && check(a, c))
      puts("Yes");
    else
      puts("No");
    return 0;
  } else {
    if (!check(b, d) || !check(a, c))
      return puts("No"), 0;
    for (int i = b; i <= d; i++) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.')
        return puts("Yes"), 0;
      // puts("N");
    }
    puts("No");
  }
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int Max = 1000000;
int N;
int A, B, C, D;
string S;
bool possi(int a, int b) {
  bool res = true;
  for (int i = a + 1; i < b; i++) {
    if (S[i] == S[i + 1] && S[i + 1] == '#')
      res = false;
  }
  return res;
}

int main() {
  cin >> N;
  cin >> A >> B >> C >> D;
  string S;
  cin >> S;

  if (C == D) {
    cout << "No" << endl;
    return 0;
  }
  if (C < D) {
    if (possi(B - 1, D - 1) && possi(A - 1, C - 1)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  if (!possi(B - 1, D - 1)) {
    // cout << 1 << endl;
    cout << "No" << endl;
    return 0;
  }
  if (!possi(A - 1, C - 1)) {
    // cout << 2 << endl;
    cout << "No" << endl;
    return 0;
  }

  for (int i = B - 1; i < D; i++) {
    if (S[i] == '.' && S[i - 1] == '.' && S[i + 1] == '.') {
      // cout << 3 << endl;
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int Max = 1000000;
int N;
int A, B, C, D;
string S;
bool possi(int a, int b) {
  bool res = true;
  for (int i = a + 1; i < b; i++) {
    if (S[i] == S[i + 1] && S[i + 1] == '#')
      res = false;
  }
  return res;
}

int main() {
  cin >> N;
  cin >> A >> B >> C >> D;
  cin >> S;

  if (C == D) {
    cout << "No" << endl;
    return 0;
  }
  if (C < D) {
    if (possi(B - 1, D - 1) && possi(A - 1, C - 1)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }

  if (!possi(B - 1, D - 1)) {
    // cout << 1 << endl;
    cout << "No" << endl;
    return 0;
  }
  if (!possi(A - 1, C - 1)) {
    // cout << 2 << endl;
    cout << "No" << endl;
    return 0;
  }

  for (int i = B - 1; i < D; i++) {
    if (S[i] == '.' && S[i - 1] == '.' && S[i + 1] == '.') {
      // cout << 3 << endl;
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}
Problem p03017 (Python)

Buggy submission (status: Runtime Error):
# https://atcoder.jp/contests/agc034/tasks/agc034_a

import sys

# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b, c, d = input_int_list()
    S = input()

    for i in range(a - 1, max(c, d) - 1):
        if S[i] == S[i + 1] == "#":
            print("No")
            quit()
    if c < d:
        print("Yes")
        quit()
    if c > d:
        for i in range(b - 2, d - 1):
            if S[i, i + 3] == "...":
                print("Yes")
                quit()
        print("No")
        quit()


if __name__ == "__main__":
    main()


Fixed submission:
# https://atcoder.jp/contests/agc034/tasks/agc034_a

import sys

# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b, c, d = input_int_list()
    S = input()

    for i in range(a - 1, max(c, d) - 1):
        if S[i] == S[i + 1] == "#":
            print("No")
            quit()
    if c < d:
        print("Yes")
        quit()
    if c > d:
        for i in range(b - 2, d - 1):
            if S[i : i + 3] == "...":
                print("Yes")
                quit()
        print("No")
        quit()


if __name__ == "__main__":
    main()
Problem p03017 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define sz(x) ((int)x.size())
#define fast_io                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
typedef long long ll;

string s;
bool can_reach(int p, int q) {
  while (p != q) {
    if (p + 1 <= q && s[p + 1] != '#') {
      p++;
    } else if (p + 2 <= q && s[p + 2] != '#') {
      p += 2;
    }
  }
  return p == q;
}

bool can_cross(int p, int q) {
  for (int i = p; i + 2 <= q; i++) {
    if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
      return 1;
    }
  }
  return 0;
}

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;
  if (can_reach(a, c) && can_reach(b, d) && c < d) {
    cout << "Yes" << endl;
  } else if (c > d && can_reach(a, c) && can_reach(b, d) &&
             can_cross(b - 1, d + 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define sz(x) ((int)x.size())
#define fast_io                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
typedef long long ll;

string s;
bool can_reach(int p, int q) {
  while (p != q) {
    if (p + 1 <= q && s[p + 1] != '#') {
      p++;
    } else if (p + 2 <= q && s[p + 2] != '#') {
      p += 2;
    } else {
      break;
    }
  }
  return p == q;
}

bool can_cross(int p, int q) {
  for (int i = p; i + 2 <= q; i++) {
    if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
      return 1;
    }
  }
  return 0;
}

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d >> s;
  a--;
  b--;
  c--;
  d--;
  if (can_reach(a, c) && can_reach(b, d) && c < d) {
    cout << "Yes" << endl;
  } else if (c > d && can_reach(a, c) && can_reach(b, d) &&
             can_cross(b - 1, d + 1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

bool check(int start, int end, string S) {
  for (int i = start; i <= end; i++) {
    if (i + 1 == end || i == end - 1)
      break;
    if (S.at(i + 1) == '#') {
      if (S.at(i + 2) == '#') {
        cout << "No" << endl;
        return 0;
      } else {
        i++;
      }
    }
  }
  return 1;
}

bool cannot_pass(string S, int b, int d) {
  for (int i = b - 1; i <= (d - 2) + 1; i++) {
    if (S.at(i) == S.at(i + 1) && S.at(i + 1) == S.at(i + 2) && S.at(i) == '.')
      return 0;
  }
  return 1;
}

int main() {
  int N, a, b, c, d;
  string S;
  cin >> N >> a >> b >> c >> d >> S;
  if (check(b - 1, d - 1, S) && check(a - 1, c - 1, S)) {
    if (d < c && cannot_pass(S, b - 1, d - 1)) {
      cout << "No" << endl;
      return 0;
    }
    cout << "Yes" << endl;
  }
}

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

bool check(int start, int end, string S) {
  for (int i = start; i <= end; i++) {
    if (i + 1 == end || i + 2 == end)
      break;
    if (S.at(i + 1) == '#') {
      if (S.at(i + 2) == '#') {
        cout << "No" << endl;
        return 0;
      } else {
        i++;
      }
    }
  }
  return 1;
}

bool cannot_pass(string S, int b, int d) {
  for (int i = b - 1; i <= (d - 2) + 1; i++) {
    if (S.at(i) == S.at(i + 1) && S.at(i + 1) == S.at(i + 2) && S.at(i) == '.')
      return 0;
  }
  return 1;
}

int main() {
  int N, a, b, c, d;
  string S;
  cin >> N >> a >> b >> c >> d >> S;
  if (check(b - 1, d - 1, S) && check(a - 1, c - 1, S)) {
    if (d < c && cannot_pass(S, b - 1, d - 1)) {
      cout << "No" << endl;
      return 0;
    }
    cout << "Yes" << endl;
  }
}
Problem p03017 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n, a, b, c, d;
string str;

bool check(ll l, ll r) {
  ll i = l;
  while (i < r) {
    if ((i + 1) < n && str[i + 1] == '.')
      i++;
    else if ((i + 2) < n && str[i + 2] == '.')
      i += 2;
  }
  if (i == r)
    return true;
  return false;
}

int main() {
  cin >> n >> a >> b >> c >> d;
  cin >> str;
  a--;
  b--;
  c--;
  d--;
  vector<bool> flg(n + 1, false);

  if (check(a, c) && check(b, d)) {
    if (c < d)
      cout << "Yes";
    else {
      ll i = a;
      flg[i] = true;
      while (i < c) {
        if ((i + 1) != c && (i + 2) < n && str[i + 2] == '.') {
          i += 2;
          flg[i] = true;
        } else if ((i + 1) < n && str[i + 1] == '.') {
          i += 1;
          flg[i] = true;
        }
      }
      i = b;
      ll tmp_flg = 0;
      while (i < d) {
        if ((i + 1) < n && str[i + 1] == '.') {
          if (flg[i] == false || flg[i + 1] == false) {
            tmp_flg = 1;
            break;
          }
          i += 1;
        } else if ((i + 2) < n && str[i + 2] == '.') {
          if (flg[i] == false || flg[i + 2] == false) {
            tmp_flg = 1;
            break;
          }
          i += 2;
        }
      }
      if (tmp_flg)
        cout << "Yes";
      else
        cout << "No";
    }
  } else
    cout << "No";
  return 0;
}


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

ll n, a, b, c, d;
string str;

bool check(ll l, ll r) {
  ll i = l;
  while (i < r) {
    if ((i + 1) < n && str[i + 1] == '.')
      i++;
    else if ((i + 2) < n && str[i + 2] == '.')
      i += 2;
    else
      break;
  }
  if (i == r)
    return true;
  return false;
}

int main() {
  cin >> n >> a >> b >> c >> d;
  cin >> str;
  a--;
  b--;
  c--;
  d--;
  vector<bool> flg(n + 1, false);

  if (check(a, c) && check(b, d)) {
    if (c < d)
      cout << "Yes";
    else {
      ll i = a;
      flg[i] = true;
      while (i < c) {
        if ((i + 1) != c && (i + 2) < n && str[i + 2] == '.') {
          i += 2;
          flg[i] = true;
        } else if ((i + 1) < n && str[i + 1] == '.') {
          i += 1;
          flg[i] = true;
        }
      }
      i = b;
      ll tmp_flg = 0;
      while (i < d) {
        if ((i + 1) < n && str[i + 1] == '.') {
          if (flg[i] == false || flg[i + 1] == false) {
            tmp_flg = 1;
            break;
          }
          i += 1;
        } else if ((i + 2) < n && str[i + 2] == '.') {
          if (flg[i] == false || flg[i + 2] == false) {
            tmp_flg = 1;
            break;
          }
          i += 2;
        }
      }
      if (tmp_flg)
        cout << "Yes";
      else
        cout << "No";
    }
  } else
    cout << "No";
  return 0;
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mp(p1, p2) make_pair(p1, p2)
#define mod 1000000007
#define PI 3.14159265358979323846
#define pii pair<ll, ll>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast ll n;
  cin >> n;
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll c;
  cin >> c;
  ll d;
  cin >> d;
  string s;
  cin >> s;
  fr(i, b - 1, d) {
    if (s[i] == '#' && s[i - 1] == '#') {
      cout << "No";
      return 0;
    }
  }
  fr(i, a - 1, c) {
    if (s[i] == '#' && s[i - 1] == '#') {
      cout << "No";
      return 0;
    }
  }
  if (c > d) {
    bool ans = false;
    if (s[b] == '.' && s[b - 2] == '.')
      ans = true;
    fr(i, b + 1, d) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.')
        ans = true;
    }
    if (s[d] == '.' && s[d - 2] == '.')
      ans = true;
    if (ans) {
      cout << "Yes";
    } else
      cout << "No";

    return 0;
  }
  cout << "Yes";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mp(p1, p2) make_pair(p1, p2)
#define mod 1000000007
#define PI 3.14159265358979323846
#define pii pair<ll, ll>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif
  fast ll n;
  cin >> n;
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll c;
  cin >> c;
  ll d;
  cin >> d;
  string s;
  cin >> s;
  fr(i, b - 1, d) {
    if (s[i] == '#' && s[i - 1] == '#') {
      cout << "No";
      return 0;
    }
  }
  fr(i, a - 1, c) {
    if (s[i] == '#' && s[i - 1] == '#') {
      cout << "No";
      return 0;
    }
  }
  if (c > d) {
    bool ans = false;
    if (s[b] == '.' && s[b - 2] == '.')
      ans = true;
    fr(i, b + 1, d) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.')
        ans = true;
    }
    if (s[d] == '.' && s[d - 2] == '.')
      ans = true;
    if (ans) {
      cout << "Yes";
    } else
      cout << "No";

    return 0;
  }
  cout << "Yes";
  return 0;
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
bool judge(int a, int b, string s) {
  for (int i = a - 1; i < b - 1; i++) {
    if (s[i] == '#' && s[i + 1] == '#') {
      return false;
    }
  }
  return true;
}
bool check(int a, int b, string s) {
  for (int i = a - 1; i <= b - 1; i++) {
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
      return true;
    }
  }
  return false;
}
int main() {
  int n, a, b, c, d;
  cin >> a >> b >> c >> d;
  string s;
  cin >> s;
  if (judge(a, c, s) && judge(b, d, s)) {
    if (c < d || check(b, d, s)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
bool judge(int a, int b, string s) {
  for (int i = a - 1; i < b - 1; i++) {
    if (s[i] == '#' && s[i + 1] == '#') {
      return false;
    }
  }
  return true;
}
bool check(int a, int b, string s) {
  for (int i = a - 1; i <= b - 1; i++) {
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
      return true;
    }
  }
  return false;
}
int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  if (judge(a, c, s) && judge(b, d, s)) {
    if (c < d || check(b, d, s)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef unsigned long long uLL;
typedef vector<int> vii;
const int inf = 1e9;
const LL INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 3e5;
char s[maxn];

bool ok(int x, int y) {
  for (int i = x + 1; i <= y; ++i) {
    if (s[i - 1] == '#' && s[i] == '#') {
      return 0;
    }
  }
  return 1;
}

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d, n;
  cin >> n >> a >> b >> c >> d >> (s + 1);
  if (s[c] == '#' || s[d] == '#' || !ok(b, d) || !ok(a, c)) {
    cout << "No" << endl;
    return 0;
  }
  if (c < d) {
    cout << "Yes" << endl;
  } else {
    for (int i = b; i <= d; ++i) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef unsigned long long uLL;
typedef vector<int> vii;
const int inf = 1e9;
const LL INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 3e5;
char s[maxn];

bool ok(int x, int y) {
  for (int i = x + 1; i <= y; ++i) {
    if (s[i - 1] == '#' && s[i] == '#') {
      return 0;
    }
  }
  return 1;
}

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d, n;
  cin >> n >> a >> b >> c >> d >> (s + 1);
  if (s[c] == '#' || s[d] == '#' || !ok(b, d) || !ok(a, c)) {
    cout << "No" << endl;
    return 0;
  }
  if (c < d) {
    cout << "Yes" << endl;
  } else {
    for (int i = b; i <= d; ++i) {
      if (s[i] == '.' && s[i - 1] == '.' && s[i + 1] == '.') {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
  return 0;
}
Problem p03017 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 100006;
int T, a, b, c, d, n;
char s[N];
bool fl;
int main() {
  scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s + 1);
  s[n + 1] = s[n + 2] = s[n + 3] = '#';
  s[b] = '#', fl = 1;
  for (; (a < c || b < d) && fl;) {
    while (a < c && a < b - 1) {
      if (a + 2 < b && a + 2 <= c && s[a + 1] == '#' && s[a + 2] != '#')
        a += 2;
      else if (a + 1 < b && a + 1 <= c && s[a + 1] != '#')
        a++;
      else
        break;
    }
    if (c > d && a == b - 1 && a + 2 <= c && s[a + 2] != '#')
      a += 2, swap(a, b), swap(c, d);
    if (a == c && b == d)
      break;
    s[b] = '.';
    if (b + 2 <= d && s[b + 1] == '#' && s[b + 2] != '#')
      b += 2, s[b] = '#';
    else if (b + 1 <= d && s[b + 1] != '#')
      b++, s[b] = '#';
    else
      fl = 0;
  }
  if (a != c || b != d)
    fl = 0;
  puts(fl ? "Yes" : "No");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200006;
int T, a, b, c, d, n;
char s[N];
bool fl;
int main() {
  scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s + 1);
  s[n + 1] = s[n + 2] = s[n + 3] = '#';
  s[b] = '#', fl = 1;
  for (; (a < c || b < d) && fl;) {
    while (a < c && a < b - 1) {
      if (a + 2 < b && a + 2 <= c && s[a + 1] == '#' && s[a + 2] != '#')
        a += 2;
      else if (a + 1 < b && a + 1 <= c && s[a + 1] != '#')
        a++;
      else
        break;
    }
    if (c > d && a == b - 1 && a + 2 <= c && s[a + 2] != '#')
      a += 2, swap(a, b), swap(c, d);
    if (a == c && b == d)
      break;
    s[b] = '.';
    if (b + 2 <= d && s[b + 1] == '#' && s[b + 2] != '#')
      b += 2, s[b] = '#';
    else if (b + 1 <= d && s[b + 1] != '#')
      b++, s[b] = '#';
    else
      fl = 0;
  }
  if (a != c || b != d)
    fl = 0;
  puts(fl ? "Yes" : "No");
}