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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int T;
  cin >> T;
  cin.ignore(1);
  while (T--) {
    set<set<pair<int, int>>> ss[2];
    for (int i = 0; i < 2; i++) {
      string str;
      getline(cin, str);
      for (int j = 0; j < 6; j++) {
        set<pair<int, int>> s;
        int y = 0, x = 0;
        for (int k = 0;; k++) {
          s.insert(make_pair(x, y)).second;
          if (k == str.size())
            break;
          static int dy[] = {-1, -1, 0, 1, 1, 0};
          static int dx[] = {0, -1, -1, 0, 1, 1};
          int idx = (j + str[k] - 'a') % 6;
          y += dy[idx];
          x += dx[idx];
        }
        int mx = 999, my = 999;
        for (auto e : s) {
          mx = min(mx, e.first);
          my = min(my, e.second);
        }
        set<pair<int, int>> ns;
        for (auto e : s) {
          ns.insert(make_pair(e.first - mx, e.second - my));
        }
        ss[i].insert(ns);
      }
    }
    cin.ignore(2);
    vector<set<pair<int, int>>> v;
    set_intersection(begin(ss[0]), end(ss[0]), begin(ss[1]), end(ss[1]),
                     back_inserter(v));
    cout << boolalpha << (!v.empty()) << endl;
  }
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int T;
  cin >> T;
  cin.ignore(2);
  while (T--) {
    set<set<pair<int, int>>> ss[2];
    for (int i = 0; i < 2; i++) {
      string str;
      getline(cin, str);
      str.erase(end(str) - 1);
      for (int j = 0; j < 6; j++) {
        set<pair<int, int>> s;
        int y = 0, x = 0;
        for (int k = 0;; k++) {
          s.insert(make_pair(x, y)).second;
          if (k == str.size())
            break;
          static int dy[] = {-1, -1, 0, 1, 1, 0};
          static int dx[] = {0, -1, -1, 0, 1, 1};
          int idx = (j + str[k] - 'a') % 6;
          y += dy[idx];
          x += dx[idx];
        }
        int mx = 999, my = 999;
        for (auto e : s) {
          mx = min(mx, e.first);
          my = min(my, e.second);
        }
        set<pair<int, int>> ns;
        for (auto e : s) {
          ns.insert(make_pair(e.first - mx, e.second - my));
        }
        ss[i].insert(ns);
      }
    }
    cin.ignore(3);
    vector<set<pair<int, int>>> v;
    set_intersection(begin(ss[0]), end(ss[0]), begin(ss[1]), end(ss[1]),
                     back_inserter(v));
    cout << boolalpha << (!v.empty()) << endl;
  }
}
Problem p00807 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

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

set<pair<int, int>> move(const string &s, int diff) {
  int x, y, mx, my;
  set<pair<int, int>> res;
  x = y = mx = my = 0;
  res.insert(make_pair(x, y));
  for (int i = 0; i < s.size(); ++i) {
    int d = (s[i] - 'a' + diff) % 6;
    x += dx[d];
    y += dy[d];
    res.insert(make_pair(x, y));
    mx = min(mx, x);
    my = min(my, y);
  }
  set<pair<int, int>> res2;
  for (set<pair<int, int>>::iterator it = res.begin(); it != res.end(); ++it) {
    res2.insert(make_pair(it->first - mx, it->second - my));
  }
  return res2;
}

int main() {
  int Tc;
  cin >> Tc;
  cin.ignore();
  for (int tc = 0; tc < Tc; ++tc) {
    string s, t, dummy;
    getline(cin, s);
    getline(cin, t);
    getline(cin, dummy);
    set<pair<int, int>> ss = move(s, 0);
    bool res = false;
    for (int i = 0; i < 6; ++i) {
      if (move(t, i) == ss) {
        res = true;
        break;
      }
    }
    if (res)
      cout << "true" << endl;
    else
      cout << "false" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

const int MAXH = 404;
const int MAXW = 404;
const int dx[6] = {1, 0, -1, -1, 0, 1};
const int dy[6] = {0, 1, 1, 0, -1, -1};

bool vis[MAXH][MAXW];
bool vis2[MAXH][MAXW];

bool move(const string &s, int x, int y, int diff) {
  vis[y][x] = true;
  for (int i = 0; i < s.size(); ++i) {
    int d = (s[i] - 'a' + diff) % 6;
    x += dx[d];
    y += dy[d];
    if (!vis2[y][x])
      return false;
    vis[y][x] = true;
  }
  return true;
}

int main() {
  int Tc;
  cin >> Tc;
  for (int tc = 0; tc < Tc; ++tc) {
    string s, t, dummy;
    cin >> s >> t >> dummy;
    fill(vis[0], vis[MAXH], false);
    fill(vis2[0], vis2[MAXH], true);
    move(s, MAXW / 2, MAXH / 2, 0);
    vector<pair<int, int>> pos;
    for (int i = 0; i < MAXH; ++i) {
      for (int j = 0; j < MAXW; ++j) {
        vis2[i][j] = vis[i][j];
      }
    }
    bool res = false;
    for (int i = 0; i < 6; ++i) {
      if (move(t, MAXW / 2, MAXH / 2, i)) {
        res = true;
        break;
      }
    }
    if (res)
      cout << "true" << endl;
    else
      cout << "false" << endl;
  }
  return 0;
}
Problem p00809 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 28)
#define MAX (1 << 13)

using namespace std;
int n, S;
short M[21];
short memo[21][MAX];

bool dfs(int phase, int nS) {
  if (memo[phase % (2 * n)][nS] != -1)
    return memo[phase % (2 * n)][nS];
  if (nS <= 1) {
    if (phase % 2)
      return 1; // enemy
    else
      return 0; // friend
  }

  bool res, update;
  update = false;
  REP(i, 1, M[phase % (2 * n)] + 1) {
    bool bres = dfs(phase + 1, nS - i);
    if (phase % 2) {
      if (!update) {
        update = true;
        res = bres;
      } else
        res &= bres;
    } else {
      if (!update) {
        update = true;
        res = bres;
      } else
        res |= bres;
    }
  }
  return memo[phase % (2 * n)][nS] = res;
}

int main() {
  while (cin >> n, n) {
    cin >> S;
    rep(i, 2 * n) cin >> M[i];
    rep(i, 21) rep(j, MAX) memo[i][j] = -1;
    // cout << "---------" <<endl;
    cout << (dfs(0, S) ? 1 : 0) << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (1 << 28)
#define MAX (1 << 13)

using namespace std;
int n, S;
short M[21];
short memo[MAX][MAX];

bool dfs(int phase, int nS) {
  if (memo[phase][nS] != -1)
    return memo[phase][nS];
  if (nS <= 1) {
    if (phase % 2)
      return 1; // enemy
    else
      return 0; // friend
  }

  bool res, update;
  update = false;
  REP(i, 1, M[phase % (2 * n)] + 1) {
    bool bres = dfs(phase + 1, nS - i);
    if (phase % 2) {
      if (!update) {
        update = true;
        res = bres;
      } else
        res &= bres;
    } else {
      if (!update) {
        update = true;
        res = bres;
      } else
        res |= bres;
    }
  }
  return memo[phase][nS] = res;
}

int main() {
  while (cin >> n, n) {
    cin >> S;
    rep(i, 2 * n) cin >> M[i];
    rep(i, MAX) rep(j, MAX) memo[i][j] = -1;
    // cout << "---------" <<endl;
    cout << (dfs(0, S) ? 1 : 0) << endl;
  }
  return 0;
}
Problem p00809 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 21;
const int MAX_S = 8200;

int n, s;
vector<int> vec;
int map[MAX_N][MAX_S];

int dp(int y, int x);

int main() {
  while (cin >> n) {
    if (n == 0)
      break;
    memset(map, -1, sizeof(map));
    vec = vector<int>(n * 2 + 1);
    // vec.clear();
    cin >> s;
    for (int i = 1; i <= (n * 2); i++)
      cin >> vec[i];
    cout << dp(1, s) << endl;
  }
  return 0;
}

// y ... 人, x ... 石
int dp(int y, int x) {
  if (map[y][x] != -1)
    return map[y][x];
  // 自分チームのターン
  if (y % 2 == 1) {
    if (x <= 1)
      return map[y][x] = 0;
    int ny = y + 1;
    // if(ny > (n * 2)) ny = 1;
    for (int i = 1; i <= vec[y]; i++) {
      if (x - i > 0) {
        if (dp(ny, x - i))
          return map[y][x] = 1;
      }
    }
    return map[y][x] = 0;
    // 相手チームのターン
  } else {
    if (x <= 1)
      return map[y][x] = 1;
    int ny = y + 1;
    if (ny > (n * 2))
      ny = 1;
    for (int i = 1; i <= vec[y]; i++) {
      if (x - i > 0) {
        if (!dp(ny, x - i))
          return map[y][x] = 0;
      }
    }
    return map[y][x] = 1;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
const int MAX_N = 21;
const int MAX_S = 8200;
const int CHECK = 10;

int n, s;
vector<int> vec(n * 2 + 1);
int map[MAX_N][MAX_S];

int dp(int y, int x);
void resetMap();

int main() {
  while (cin >> n) {
    if (n == 0)
      break;
    resetMap();
    // vec.clear();
    cin >> s;
    for (int i = 1; i <= (n * 2); i++)
      cin >> vec[i];
    cout << dp(1, s) << endl;
  }
  return 0;
}

// y ... 人, x ... 石
int dp(int y, int x) {
  if (map[y][x] != -1)
    return map[y][x];
  // 自分チームのターン
  if (y % 2 == 1) {
    if (x <= 1)
      return map[y][x] = 0;
    int ny = y + 1;
    if (ny > (n * 2))
      ny = 1;
    for (int i = 1; i <= vec[y]; i++) {
      if (x - i > 0) {
        if (dp(ny, x - i))
          return map[y][x] = 1;
      }
    }
    return map[y][x] = 0;
    // 相手チームのターン
  } else {
    if (x <= 1)
      return map[y][x] = 1;
    int ny = y + 1;
    if (ny > (n * 2))
      ny = 1;
    for (int i = 1; i <= vec[y]; i++) {
      if (x - i > 0) {
        if (!dp(ny, x - i))
          return map[y][x] = 0;
      }
    }
    return map[y][x] = 1;
  }
}

void resetMap() {
  for (int i = 0; i < MAX_N; i++) {
    for (int j = 0; j < MAX_S; j++) {
      map[i][j] = -1;
    }
  }
}
Problem p00809 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int s, n, a[25], dp[10000][25];
int solve(int r, int s) {
  if (r == 0) {
    dp[r][s] = 0;
    return 0;
  }
  if (dp[r][s] >= 0)
    return dp[r][s];
  int flag = 0;
  for (int i = 1; i <= a[s]; i++) {
    if (r - i < 0)
      continue;
    if (solve(r - i, (s + 1) % n) == false)
      flag = 1;
  }
  dp[r][s] = flag;
  return flag;
}
int main() {
  while (true) {
    for (int i = 0; i < 10000; i++) {
      for (int j = 0; j < 25; j++)
        dp[i][j] = -1;
    }
    cin >> n;
    if (n == 0)
      break;
    cin >> s;
    s--;
    n *= 2;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    cout << solve(s, 0) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int s, n, a[15], dp[10000][15];
int solve(int r, int s) {
  if (r == 0) {
    dp[r][s] = 0;
    return 0;
  }
  if (dp[r][s] >= 0)
    return dp[r][s];
  int flag = 0;
  for (int i = 1; i <= a[s]; i++) {
    if (r - i < 0)
      continue;
    if (solve(r - i, (s + 1) % n) == false)
      flag = 1;
  }
  dp[r][s] = flag;
  return flag;
}
int main() {
  while (true) {
    for (int i = 0; i < 10000; i++) {
      for (int j = 0; j < 15; j++)
        dp[i][j] = -1;
    }
    cin >> n;
    if (n == 0)
      break;
    cin >> s;
    s--;
    n *= 2;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    cout << solve(s, 0) << endl;
  }
  return 0;
}
Problem p00810 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <valarray>

using namespace std;

double dist(valarray<double> a, valarray<double> b) {
  double s = 0;
  for (int i = 0; i < 3; i++) {
    s += (a[i] - b[i]) * (a[i] - b[i]);
  }
  return sqrt(s);
}

int main() {
  for (int n; cin >> n, n;) {
    valarray<double> p[30];
    for (int i = 0; i < n; i++) {
      p[i].resize(3);
      cin >> p[i][0] >> p[i][1] >> p[i][2];
    }
    valarray<double> c(50, 3);
    double w = 1;
    double ld;
    for (int i = 0; i < 100000; i++, w *= .999) {
      double m = -1;
      int x;
      for (int j = 0; j < n; j++) {
        auto d = dist(p[j], c);
        if (d > m) {
          m = d;
          x = j;
        }
      }
      ld = m;
      valarray<double> v = p[x] - c;
      c += v * w;
    }
    cout.precision(5);
    cout << fixed << ld << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <valarray>

using namespace std;

double dist(valarray<double> a, valarray<double> b) {
  double s = 0;
  for (int i = 0; i < 3; i++) {
    s += (a[i] - b[i]) * (a[i] - b[i]);
  }
  return sqrt(s);
}

int main() {
  for (int n; cin >> n, n;) {
    valarray<double> p[30];
    for (int i = 0; i < n; i++) {
      p[i].resize(3);
      cin >> p[i][0] >> p[i][1] >> p[i][2];
    }
    valarray<double> c(50, 3);
    double w = 10;
    for (int i = 0; i < 1000000; i++, w *= .9999) {
      double m = -1;
      int x;
      for (int j = 0; j < n; j++) {
        auto d = dist(p[j], c);
        if (d > m) {
          m = d;
          x = j;
        }
      }
      valarray<double> v = p[x] - c;
      c += v * w / dist(v, {0, 0, 0});
    }
    cout.precision(5);
    cout << fixed << dist(c, p[0]) << endl;
  }
}
Problem p00810 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#define pow2(x) ((x) * (x))
using namespace std;
struct three_d {
  double x, y, z;
} stars[31];
int n;

double distancex(three_d from, int to) {
  return pow2(from.x - stars[to].x) + pow2(from.y - stars[to].y) +
         pow2(from.z - stars[to].z);
}

int main() {
  while ((cin >> n), n) {
    for (int i = 0; i < n; i++)
      cin >> stars[i].x >> stars[i].y >> stars[i].z;
    double move = 0.5, maxdis;
    three_d now = {0, 0, 0};
    int moveto = 0, i;
    while (move > 0.000000001) {
      for (int j = 0; j < 1000; j++) {
        now.x = now.x * (1 - move) + stars[moveto].x * move;
        now.y = now.y * (1 - move) + stars[moveto].y * move;
        now.z = now.z * (1 - move) + stars[moveto].z * move;
        moveto = 0;
        maxdis = 0;
        for (i = 0; i < n; i++)
          if (distancex(now, i) > maxdis) {
            maxdis = distancex(now, i);
            moveto = i;
          }
      }
      move /= 2;
    }
    printf("%.5lf\\n", sqrt(maxdis));
  }
}

Error: -11

Fixed submission:

#include <cmath>
#include <iostream>
#define pow2(x) ((x) * (x))
using namespace std;
struct three_d {
  double x, y, z;
} stars[32];
int n;

double distancex(three_d from, int to) {
  return pow2(from.x - stars[to].x) + pow2(from.y - stars[to].y) +
         pow2(from.z - stars[to].z);
}

int main() {
  while ((cin >> n), n) {
    for (int i = 0; i < n; i++)
      cin >> stars[i].x >> stars[i].y >> stars[i].z;
    double move = 0.5, maxdis;
    three_d now = {0, 0, 0};
    int moveto, i;
    while (move > 0.000000001) {
      for (int j = 0; j < 1000; j++) {
        now.x = now.x * (1 - move) + stars[moveto].x * move;
        now.y = now.y * (1 - move) + stars[moveto].y * move;
        now.z = now.z * (1 - move) + stars[moveto].z * move;
        moveto = 0;
        maxdis = 0;
        for (i = 0; i < n; i++)
          if (distancex(now, i) > maxdis) {
            maxdis = distancex(now, i);
            moveto = i;
          }
      }
      move /= 2;
    }
    printf("%.5lf\\n", sqrt(maxdis));
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n = 100000;
  vector<bool> p(n + 1, true);
  for (int i = 2; i <= n; i++) {
    if (p[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        p[j] = false;
      }
    }
  }
  vector<int> v;
  for (int i = 2; i <= n; i++) {
    if (p[i])
      v.push_back(i);
  }

  int m, a, b;
  while (cin >> m >> a >> b, m) {
    int p = 0, q = 0;
    for (int i = 0; i < v.size(); i++) {
      for (int j = i; j < v.size() && (long long)v[i] * v[j] <= (long long)m &&
                      a * v[j] <= b * v[i];
           j++) {
        if (v[i] * v[j] > v[p] * v[q]) {
          p = i;
          q = j;
        }
      }
    }
    cout << v[p] << " " << v[q] << endl;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n = 100000;
  vector<bool> p(n + 1, true);
  for (int i = 2; i <= n; i++) {
    if (p[i]) {
      for (int j = 2 * i; j <= n; j += i) {
        p[j] = false;
      }
    }
  }
  vector<int> v;
  for (int i = 2; i <= n; i++) {
    if (p[i]) {
      v.push_back(i);
    }
  }

  int m, a, b;
  while (cin >> m >> a >> b, m) {
    int h = v.front(), w = v.front();
    for (auto j = begin(v); j != end(v); j++) {
      for (auto i = j; i != end(v); i++) {
        if (*i * *j > m || b * *j < a * *i) {
          break;
        }
        if (*i * *j > h * w) {
          h = *i;
          w = *j;
        }
      }
    }
    cout << w << " " << h << endl;
  }
}
Problem p00811 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

const double EPS = 1.0e-9;

int main() {
  vector<int> prime;
  prime.push_back(2);
  prime.push_back(3);

  for (int i = 4; i < 10000; i++) {
    bool flag = true;

    for (int j = 0; j < prime.size(); j++) {
      if (i % prime[j] == 0) {
        flag = false;
        break;
      }
    }

    if (flag == true) {
      prime.push_back(i);
    }
  }

  while (true) {
    int m, a, b;

    cin >> m >> a >> b;

    if (m == 0 && a == 0 && b == 0) {
      break;
    }

    int ansp, ansq;
    int maxarea = 0;

    rep(i, prime.size()) {
      for (int j = i; j < prime.size(); j++) {
        if (prime[i] * prime[j] <= m &&
            ((double)a / b <= (double)prime[i] / prime[j] ||
             fabs((double)a / b - (double)prime[i] / prime[j]) < EPS) &&
            (double)prime[i] / prime[j] <= 1) {
          if (prime[i] * prime[j] > maxarea) {
            maxarea = prime[i] * prime[j];
            ansp = prime[i];
            ansq = prime[j];
          }
        }
      }
    }

    cout << ansp << " " << ansq << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

const double EPS = 1.0e-9;

int main() {
  vector<int> prime;
  prime.push_back(2);
  prime.push_back(3);

  for (int i = 4; i < 100000; i++) {
    bool flag = true;

    for (int j = 0; j < prime.size(); j++) {
      if (i % prime[j] == 0) {
        flag = false;
        break;
      }
    }

    if (flag == true) {
      prime.push_back(i);
    }
  }

  while (true) {
    int m, a, b;

    cin >> m >> a >> b;

    if (m == 0 && a == 0 && b == 0) {
      break;
    }

    int ansp, ansq;
    int maxarea = 0;

    rep(i, prime.size()) {
      for (int j = i; j < prime.size(); j++) {
        if (prime[i] * prime[j] <= m &&
            ((double)a / b <= (double)prime[i] / prime[j] ||
             fabs((double)a / b - (double)prime[i] / prime[j]) < EPS) &&
            (double)prime[i] / prime[j] <= 1) {
          if (prime[i] * prime[j] > maxarea) {
            maxarea = prime[i] * prime[j];
            ansp = prime[i];
            ansq = prime[j];
          }
        }
      }
    }

    cout << ansp << " " << ansq << endl;
  }

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

///
// File:  1232.cpp
// Author: ymiyamoto
//
// Created on Sat Nov 25 19:23:48 2017
//

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(uint32_t n) {
  for (uint32_t i = 2; i <= (uint32_t)sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

vector<uint32_t> primes_up_to(uint32_t n) {
  vector<uint32_t> primes;
  for (uint32_t i = 2; i <= n; i++) {
    if (is_prime(i)) {
      primes.push_back(i);
    }
  }

  return primes;
}

int32_t main() {
  vector<uint32_t> primes = primes_up_to(100000);

  while (true) {
    uint32_t m, a, b;
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;

    uint32_t max_p = 0;
    uint32_t max_q = 0;
    for (uint32_t i = 0; i < primes.size(); i++) {
      uint32_t q = primes[i];
      if (q > m)
        break;
      auto start =
          lower_bound(primes.begin(), primes.end(), ceil((double)a * q / b));
      auto end = upper_bound(primes.begin(), primes.end(), min(q, m / q));
      for (auto iter = start; iter < end; iter++) {
        uint32_t p = *iter;
        if (max_p * max_q < p * q) {
          max_p = p;
          max_q = q;
        }
      }
    }
    cout << max_p << " " << max_q << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

///
// File:  1232.cpp
// Author: ymiyamoto
//
// Created on Sat Nov 25 19:23:48 2017
//

#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(uint32_t n) {
  for (uint32_t i = 2; i <= (uint32_t)sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

vector<uint32_t> primes_up_to(uint32_t n) {
  vector<uint32_t> primes;
  for (uint32_t i = 2; i <= n; i++) {
    if (is_prime(i)) {
      primes.push_back(i);
    }
  }

  return primes;
}

int32_t main() {
  vector<uint32_t> primes = primes_up_to(100000);

  while (true) {
    uint32_t m, a, b;
    cin >> m >> a >> b;
    if (m == 0 && a == 0 && b == 0)
      break;

    uint32_t max_p = 0;
    uint32_t max_q = 0;
    for (uint32_t i = 0; i < primes.size(); i++) {
      uint32_t p = primes[i];
      if (p > m)
        continue;
      for (uint32_t j = i; j < primes.size(); j++) {
        uint32_t q = primes[j];
        if (q > m)
          break;
        if (p * q <= m && a * q <= b * p) {
          if (max_p * max_q < p * q) {
            max_p = p;
            max_q = q;
          }
        }
      }
    }

    cout << max_p << " " << max_q << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(int n, int k = 2) {
  if (n == 1) {
    return false;
  }

  if (n < k * k) {
    return true;
  }

  if (n % k == 0) {
    return false;
  }

  return is_prime(n, k + 1);
}

int main() {
  vector<int> prime;

  for (int i = 2; i <= 100000; i++) {
    if (is_prime(i)) {
      prime.push_back(i);
    }
  }

  int m, a, b;

  while (true) {
    cin >> m >> a >> b;

    if (m == 0 && a == 0 && b == 0) {
      break;
    }

    int max_ = 0, p = 0, q = 0;

    for (int i = 0; i < prime.size(); i++) {
      for (int j = i; j < prime.size() && (prime[i] * prime[j] <= m); j++) {
        if (a * prime[j] <= b * prime[i] && 1LL * prime[i] * prime[j] <= m) {
          if (max_ < prime[i] * prime[j]) {
            max_ = prime[i] * prime[j];

            p = prime[i];
            q = prime[j];
          }
        }
      }
    }

    cout << p << ' ' << q << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(int n, int k = 2) {
  if (n == 1) {
    return false;
  }

  if (n < k * k) {
    return true;
  }

  if (n % k == 0) {
    return false;
  }

  return is_prime(n, k + 1);
}

int main() {
  vector<int> prime;

  for (int i = 2; i <= 111111; i++) {
    if (is_prime(i)) {
      prime.push_back(i);
    }
  }

  int m, a, b;

  while (true) {
    cin >> m >> a >> b;

    if (m == 0 && a == 0 && b == 0) {
      break;
    }

    int max_ = 0, p = 0, q = 0;

    for (int i = 0; i < prime.size(); i++) {
      for (int j = i; (prime[i] * prime[j] <= m); j++) {
        if (a * prime[j] <= b * prime[i]) {
          if (max_ < prime[i] * prime[j]) {
            max_ = prime[i] * prime[j];

            p = prime[i];
            q = prime[j];
          }
        }
      }
    }

    cout << p << ' ' << q << endl;
  }

  return 0;
}