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

//
//  main.cpp
//  L
//
//  Created by LucienShui on 2017/4/20.
//  Copyright ? 2017年 LucienShui. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define mfor(i, n) for (int i = 0; i < n; ++i)

using namespace std;

long long a[1005];

bool panduan(long long a) {
  while (a / 10) {
    long long t = a % 10;
    a /= 10;
    if (a % 10 != t - 1)
      return false;
  }
  return true;
}
int main() {
  long long n, cnt = 0, result = -1, t;
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++)
    scanf("%lld", a + i);
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      t = a[i] * a[j];
      if (panduan(t))
        result = max(t, result);
    }
  }
  printf("%lld\\n", result);
  return 0;
}

Error: TLE

Fixed submission:

//
//  main.cpp
//  L
//
//  Created by LucienShui on 2017/4/20.
//  Copyright ? 2017年 LucienShui. All rights reserved.
//

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define mfor(i, n) for (int i = 0; i < n; ++i)

using namespace std;

long long a[1005];

bool panduan(long long a) {
  while (a / 10) {
    long long t = a % 10;
    a /= 10;
    if (a % 10 != t - 1)
      return false;
  }
  return true;
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  long long n, cnt = 0, result = -1, t;
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++)
    scanf("%lld", a + i);
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      t = a[i] * a[j];
      if (panduan(t))
        result = max(t, result);
    }
  }
  printf("%lld\\n", result);
  return 0;
}
Problem p01880 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 1010
using namespace std;
int n;

int a[N];

bool check(int pro) {
  static int bit[12];
  int len;
  for (len = 1; pro; ++len) {
    bit[len] = pro % 10;
    pro /= 10;
  }
  len--;
  for (int i = 1; i <= len; ++i) {
    if (bit[1] - bit[i] != i - 1)
      return false;
  }
  return true;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  int ans = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < i; ++j) {
      if (check(a[i] * a[j])) {
        ans = max(ans, a[i] * a[j]);
      }
    }
  }
  printf("%d\\n", ans);
}

Error: 2

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
int n, a[1001];
std::vector<int> s;
bool check(int k) {
  int l = k % 10;
  k /= 10;
  while (k)
    if (k % 10 != l - 1)
      return false;
    else
      l = k % 10, k /= 10;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      s.push_back(a[i] * a[j]);
  sort(s.begin(), s.end());
  for (int i = s.size() - 1; i >= 0; i--)
    if (check(s[i]))
      return printf("%d\\n", s[i]);
  printf("-1\\n");
  return 0;
}
Problem p01880 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) { cin >> v[i]; }
  vs s;
  string t = "123456789";
  rep(i, n - 1) range(j, i + 1, n) {
    string x = to_string(v[i] * v[j]);
    if (t.find(x) != string::npos)
      s.push_back(x);
  }
  sort(all(s), [](string a, string b) {
    return a.length() > b.length() || (a.length() == b.length() && a[0] > b[0]);
  });
  if (s.size()) {
    cout << s[0] << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) { cin >> v[i]; }
  vs s;
  string t = "123456789";
  rep(i, n - 1) range(j, i + 1, n) {
    string x = to_string(v[i] * v[j]);
    if (t.find(x) != string::npos)
      s.push_back(x);
  }
  sort(all(s), [](string a, string b) {
    return a.length() > b.length() || (a.length() == b.length() && a[0] > b[0]);
  });
  cout << s[0] << endl;
}
Problem p01881 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>
#include <tuple>

using namespace std;

using T3 = tuple<int, int, int>;

int main() {
  int H, W;
  cin >> H >> W;
  char M[H][W];
  int dist[H][W];
  queue<T3> Q;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> M[i][j];
      if (M[i][j] == '%') {
        dist[i][j] = 0;
        Q.push(T3(i, j, 0));
      } else {
        dist[i][j] = 1000000;
      }
    }
  }
  int dist_p = 1000000, dist_s = 1000000;
  while (!Q.empty()) {
    int i, j, d;
    tie(i, j, d) = Q.front();
    Q.pop();
    if (M[i][j] == '@')
      dist_p = d;
    if (M[i][j] == '$')
      dist_s = min(dist_s, d);
    int diff[5] = {0, -1, 0, 1, 0};
    for (int k = 0; k < 4; k++) {
      if (i + diff[k] < 0 || i + diff[k] >= H || j + diff[k + 1] < 0 ||
          j + diff[k + 1] >= W)
        continue;
      if (M[i + diff[k]][j + diff[k + 1]] != '#' &&
          dist[i + diff[k]][j + diff[k + 1]] == 1000000) {
        dist[i + diff[k]][j + diff[k + 1]] = d + 1;
        Q.push(T3(i + diff[k], j + diff[k + 1], d + 1));
      }
    }
  }
  if (dist_p < dist_s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <queue>
#include <tuple>

using namespace std;

using T3 = tuple<int, int, int>;

int main() {
  int H, W;
  cin >> H >> W;
  char M[H][W];
  int dist[H][W];
  queue<T3> Q;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> M[i][j];
      if (M[i][j] == '%') {
        dist[i][j] = 0;
        Q.push(T3(i, j, 0));
      } else {
        dist[i][j] = 1000000;
      }
    }
  }
  int dist_p = 1000000, dist_s = 1000000;
  while (!Q.empty()) {
    int i, j, d;
    tie(i, j, d) = Q.front();
    Q.pop();
    if (dist[i][j] < d)
      continue;
    else
      dist[i][j] = d;
    if (M[i][j] == '@')
      dist_p = d;
    if (M[i][j] == '$')
      dist_s = min(dist_s, d);
    int diff[5] = {0, -1, 0, 1, 0};
    for (int k = 0; k < 4; k++) {
      if (i + diff[k] < 0 || i + diff[k] >= H || j + diff[k + 1] < 0 ||
          j + diff[k + 1] >= W)
        continue;
      if (M[i + diff[k]][j + diff[k + 1]] != '#' &&
          dist[i + diff[k]][j + diff[k + 1]] == 1000000) {
        Q.push(T3(i + diff[k], j + diff[k + 1], d + 1));
      }
    }
  }
  if (dist_p < dist_s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

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

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

  int sx, sy;
  vector<vector<char>> map(h + 2, vector<char>(w + 2, '#'));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> map[i][j];
      if (map[i][j] == '%') {
        sy = i;
        sx = j;
      }
    }
  }

  queue<pair<int, pair<int, int>>> q;
  q.push(make_pair(0, make_pair(sy, sx)));
  map[sy][sx] = '#';
  int princess = 1e9;
  int soldier = 1e9;
  while (!q.empty()) {
    int step = q.front().first;
    int y = q.front().second.first;
    int x = q.front().second.second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (map[ny][nx] != '#') {
        if (map[ny][nx] == '@')
          princess = step;
        if (map[ny][nx] == '$')
          soldier = min(step, soldier);
        map[ny][nx] = '#';
        q.push(make_pair(step + 1, make_pair(ny, nx)));
      }
    }
  }

  if (princess < soldier) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

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

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

  int sx, sy;
  vector<vector<char>> map(h + 2, vector<char>(w + 2, '#'));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> map[i][j];
      if (map[i][j] == '%') {
        sy = i;
        sx = j;
      }
    }
  }

  queue<pair<int, pair<int, int>>> q;
  q.push(make_pair(0, make_pair(sy, sx)));
  int princess = 1e9;
  int soldier = 1e9;
  while (!q.empty()) {
    int step = q.front().first;
    int y = q.front().second.first;
    int x = q.front().second.second;
    q.pop();
    if (map[y][x] == '@') {
      princess = step;
    }
    if (map[y][x] == '$') {
      soldier = step;
    }
    map[y][x] = '#';

    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (map[ny][nx] != '#') {
        q.push(make_pair(step + 1, make_pair(ny, nx)));
      }
    }
  }

  if (princess < soldier) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p01881 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
const int INF = numeric_limits<int>::max() / 2;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  int sx, sy, px, py;
  for (int i = 0; i < h; i++) {
    cin >> v[i];
    for (int j = 0; j < w; j++) {
      if (v[i][j] == '%') {
        sx = i;
        sy = j;
      } else if (v[i][j] == '@') {
        px = i;
        py = j;
      }
    }
  }
  vector<vector<int>> dis(300, vector<int>(300, INF));
  dis[sx][sy] = 0;
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  queue<P> q;
  q.push(P(sx, sy));
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || h <= nx || ny < 0 || w <= ny)
        continue;
      if (v[nx][ny] == '#')
        continue;
      if (dis[nx][ny] != INF)
        continue;
      dis[nx][ny] = dis[x][y] + 1;
      q.push(P(nx, ny));
    }
  }
  int pdis = dis[px][py];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] != '$')
        continue;
      if (dis[i][j] <= pdis) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
const int INF = numeric_limits<int>::max() / 2;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  vector<string> v(h);
  int sx, sy, px, py;
  for (int i = 0; i < h; i++) {
    cin >> v[i];
    for (int j = 0; j < w; j++) {
      if (v[i][j] == '%') {
        sx = i;
        sy = j;
      } else if (v[i][j] == '@') {
        px = i;
        py = j;
      }
    }
  }
  vector<vector<int>> dis(300, vector<int>(300, INF));
  dis[sx][sy] = 0;
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  queue<P> q;
  q.push(P(sx, sy));
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    int x = p.first, y = p.second;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || h <= nx || ny < 0 || w <= ny)
        continue;
      if (v[nx][ny] == '#')
        continue;
      if (dis[nx][ny] != INF)
        continue;
      dis[nx][ny] = dis[x][y] + 1;
      q.push(P(nx, ny));
    }
  }
  int pdis = dis[px][py];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (v[i][j] != '$')
        continue;
      if (dis[i][j] <= pdis) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p01881 (C++) — buggy submission, verdict: Runtime Error

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

int H, W;
char t[200][200];
int si, sj, ti, tj;
int d[200][200];
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> t[i][j];
      if (t[i][j] == '@') {
        si = i;
        sj = j;
      }
      if (t[i][j] == '%') {
        ti = i;
        tj = j;
      }
    }
  }
  memset(d, 1, sizeof(d));
  d[ti][tj] = 0;
  queue<int> qi, qj;
  qi.push(ti);
  qj.push(tj);
  while (!qi.empty()) {
    int pi = qi.front();
    qi.pop();
    int pj = qj.front();
    qj.pop();
    for (int dir = 0; dir < 4; dir++) {
      int ni = pi + di[dir];
      int nj = pj + dj[dir];
      if (ni < 0 || nj < 0 || ni >= H || nj >= W)
        continue;
      if (t[ni][nj] == '#')
        continue;
      if (d[ni][nj] > d[pi][pj] + 1) {
        d[ni][nj] = d[pi][pj] + 1;
        qi.push(ni);
        qj.push(nj);
      }
    }
  }
  int dist = d[si][sj];
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      if (t[i][j] == '$')
        if (d[i][j] <= dist)
          dist = 0;
  if (dist)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: WA

Fixed submission:

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

int H, W;
char t[100][100];
int si, sj, ti, tj;
int d[100][100];
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> t[i][j];
      if (t[i][j] == '@') {
        si = i;
        sj = j;
      }
      if (t[i][j] == '%') {
        ti = i;
        tj = j;
      }
    }
  }
  memset(d, 1, sizeof(d));
  d[ti][tj] = 0;
  queue<int> qi, qj;
  qi.push(ti);
  qj.push(tj);
  while (!qi.empty()) {
    int pi = qi.front();
    qi.pop();
    int pj = qj.front();
    qj.pop();
    for (int dir = 0; dir < 4; dir++) {
      int ni = pi + di[dir];
      int nj = pj + dj[dir];
      if (ni < 0 || nj < 0 || ni >= H || nj >= W)
        continue;
      if (t[ni][nj] == '#')
        continue;
      if (d[ni][nj] > d[pi][pj] + 1) {
        d[ni][nj] = d[pi][pj] + 1;
        qi.push(ni);
        qj.push(nj);
      }
    }
  }
  int dist = d[si][sj];
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      if (t[i][j] == '$')
        if (d[i][j] <= dist)
          dist = 0;
  if (dist)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01881 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define mk make_pair
using namespace std;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int main() {
  int h, w, x, y, sol = 0, pri = 0;
  cin >> h >> w;
  bool b[h][w];
  string s[h];
  r(i, h) cin >> s[i];
  r(i, h) r(j, w) if (s[i][j] == '%') x = j, y = i;
  r(i, h) r(j, w) b[i][j] = 0;
  queue<pair<int, int>> Q;
  queue<int> q1;
  q1.push(0);
  Q.push(mk(y, x));
  b[y][x] = 1;
  while (!Q.empty()) {
    pair<int, int> a = Q.front();
    Q.pop();
    int xx = a.second, yy = a.first, cc = q1.front();
    q1.pop();
    if (pri && pri < cc)
      break;
    if (s[yy][xx] == '$') {
      sol = cc;
      break;
    }
    if (s[yy][xx] == '@') {
      pri = cc;
    }
    r(i, 4) {
      int x1 = xx + dx[i], y1 = yy + dy[i];
      if (x1 < 0 || x1 >= w || y1 < 0 || y1 >= h || b[y1][x1] ||
          s[y1][x1] == '#')
        continue;
      Q.push(mk(y1, x1));
      b[y1][x1] = 1;
      q1.push(cc + 1);
    }
  }
  if (sol == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define mk make_pair
using namespace std;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int main() {
  int h, w, x, y, sol = 0, pri = 0;
  cin >> h >> w;
  bool b[h][w];
  string s[h];
  r(i, h) cin >> s[i];
  r(i, h) r(j, w) if (s[i][j] == '%') x = j, y = i;
  r(i, h) r(j, w) b[i][j] = 0;
  queue<pair<int, int>> Q;
  queue<int> q1;
  q1.push(0);
  Q.push(mk(y, x));
  while (!Q.empty()) {
    pair<int, int> a = Q.front();
    Q.pop();
    int xx = a.second, yy = a.first, cc = q1.front();
    q1.pop();
    b[yy][xx] = 1;
    if (pri && pri < cc)
      break;
    if (s[yy][xx] == '$') {
      sol = cc;
    }
    if (s[yy][xx] == '@') {
      pri = cc;
    }
    if (sol)
      break;
    r(i, 4) {
      int x1 = xx + dx[i], y1 = yy + dy[i];
      if (x1 < 0 || x1 >= w || y1 < 0 || y1 >= h || b[y1][x1] ||
          s[y1][x1] == '#')
        continue;
      Q.push(mk(y1, x1));
      q1.push(cc + 1);
    }
  }
  if (sol == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p01881 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, (n))
#define ALL(a) (a.begin(), a.end())
typedef vector<int> vi;

constexpr int INF = 1000000000;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> t(h);
  int pi, pj, hi, hj;
  vi si, sj;
  REP(i, h) {
    cin >> t[i];
    REP(j, w) {
      switch (t[i][j]) {
      case '@':
        pi = i;
        pj = j;
        break;
      case '%':
        hi = i;
        hj = j;
        break;
      case '$':
        si.push_back(i);
        sj.push_back(j);
      }
    }
  }
  vector<vi> dist(h, vi(w, INF));
  dist[hi][hj] = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(hi, hj));
  while (!que.empty()) {
    int i, j;
    tie(i, j) = que.front();
    que.pop();
    int di[] = {1, 0, -1, 0};
    int dj[] = {0, 1, 0, -1};
    REP(k, 4) {
      int ni = i + di[k];
      int nj = j + dj[k];
      if (ni < 0 || nj < 0 || ni >= h || nj >= w)
        continue;
      if (t[ni][nj] == '#')
        continue;
      if (dist[ni][nj] <= dist[i][j] + 1)
        continue;
      dist[ni][nj] = dist[i][j] + 1;
      que.push(make_pair(ni, nj));
    }
  }
  int pd = dist[pi][pj];
  bool valid = true;
  REP(i, si.size()) {
    if (dist[si[i]][sj[i]] <= pd) {
      valid = false;
    }
  }
  if (valid) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, (n))
#define ALL(a) (a.begin(), a.end())
typedef vector<int> vi;

constexpr int INF = 1000000000;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> t(h);
  int pi, pj, hi, hj;
  vi si, sj;
  REP(i, h) {
    cin >> t[i];
    REP(j, w) {
      switch (t[i][j]) {
      case '@':
        pi = i;
        pj = j;
        break;
      case '%':
        hi = i;
        hj = j;
        break;
      case '$':
        si.push_back(i);
        sj.push_back(j);
      }
    }
  }
  vector<vi> dist(h, vi(w, INF));
  dist[hi][hj] = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(hi, hj));
  while (!que.empty()) {
    int i, j;
    tie(i, j) = que.front();
    que.pop();
    int di[] = {1, 0, -1, 0};
    int dj[] = {0, 1, 0, -1};
    REP(k, 4) {
      int ni = i + di[k];
      int nj = j + dj[k];
      if (ni < 0 || nj < 0 || ni >= h || nj >= w)
        continue;
      if (t[ni][nj] == '#')
        continue;
      if (dist[ni][nj] <= dist[i][j])
        continue;
      dist[ni][nj] = dist[i][j] + 1;
      que.push(make_pair(ni, nj));
    }
  }
  int pd = dist[pi][pj];
  bool valid = true;
  REP(i, si.size()) {
    if (dist[si[i]][sj[i]] <= pd) {
      valid = false;
    }
  }
  if (valid) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p01883 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;

int a;
int main() {
  int n = 0, k;
  scanf("%d", &a);
  while (1) {
    if (n * (n + 1) / 2 >= a)
      break;
    n++;
  }
  k = n * (n + 1) / 2 - a;
  for (int i = 0; i < n - k; i++)
    printf(")");

  printf("(");

  for (int i = 0; i < k; i++)
    printf(")");

  for (int i = 0; i < n - 1; i++)
    printf("(");

  printf("\\n");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define READ() freopen("in.txt", "r", stdin)
#define WRITE() freopen("out.txt", "w", stdout)
#define sf(n) scanf("%d", &n)
#define sl(x) scanf("%I64d", &x)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)
#define mem(x, y) memset(x, y, sizeof(x))
#define D(x) cout << #x << " = " << x << endl
#define YOLO cout << "YOLO" << endl
#define NL printf("\\n")
#define EPS 1e-10
#define INF INT_MAX
#define MAX 100010
#define MOD 1000000007
#define LL long long
#define endl "\\n"
#define pi 2.0 * acos(0.0)
#define cnd tree[idx]
#define lnd tree[left]
#define rnd tree[right]
#define callLeft left, st, mid
#define callRight right, mid + 1, ed

LL cumSum[MAX];
int mxI;

void preCal() {
  cumSum[0] = 0;
  cumSum[1] = 1;
  for (int i = 2; i < MAX; i++) {
    cumSum[i] = cumSum[i - 1] + i;
    if (cumSum[i] > 1000000009) {
      //            YOLO;
      //            cout << i << endl;
      mxI = i;
      break;
    }
  }
}

int main() {
  //	ios_base::sync_with_stdio(false);
  //    cin.tie(0); /// use "\\n" instead of endl
  //    READ();
  //    WRITE();

  preCal();

  LL n;
  cin >> n;

  stack<string> stk;

  LL valI = lower_bound(cumSum, cumSum + mxI, n) - cumSum;

  if (n == cumSum[valI]) {
    for (int i = 0; i < valI; i++) {
      cout << ")";
    }
    for (int i = 0; i < valI; i++) {
      cout << "(";
    }
  } else {
    valI--;
    while (1) {
      string sTemp = "";
      for (int i = 0; i < valI; i++) {
        //                cout << ")";
        sTemp += ')';
      }
      for (int i = 0; i < valI; i++) {
        //                cout << "(";
        sTemp += '(';
      }
      stk.push(sTemp);
      if (n == cumSum[valI]) {
        break;
      }
      n = n - cumSum[valI];
      if (n == 0)
        break;
      valI = lower_bound(cumSum, cumSum + mxI, n) - cumSum;
    }

    while (!stk.empty()) {
      cout << stk.top();
      stk.pop();
    }
  }
  cout << endl;

  return 0;
}