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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
double key[100][100];
double table[100][100];

void Init(int n, int m) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      table[i][j] = 0;
}

double memo(int cur, int count, int limit, int kind) {
  if (table[cur][count])
    return table[cur][count];
  if (count == limit)
    return 1.0;
  for (int i = 0; i < kind; i++)
    table[cur][count] =
        max(table[cur][count], memo(i, count + 1, limit, kind) * key[i][cur]);
  return table[cur][count];
}

int main() {
  int n, m;
  while (cin >> n >> m && ((n != 0) || (m != 0))) {
    Init(n, m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> key[i][j];
    for (int i = 0; i < n; i++)
      table[i][0] = memo(i, 0, m - 1, n);
    double max = 0;
    for (int i = 0; i < n; i++)
      if (max < table[i][0])
        max = table[i][0];
    printf("%0.2f\\n", max);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
double key[100][100];
double table[100][100];

void Init(int n, int m) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      table[i][j] = 0;
}

double memo(int cur, int count, int limit, int kind) {
  if (table[cur][count])
    return table[cur][count];
  if (count == limit)
    return 1.0;
  double Max = 0;
  int prev = 0;
  for (int i = 0; i < kind; i++) {
    double tmp = memo(i, count + 1, limit, kind);
    if (Max <= tmp) {
      // if(Max*key[prev][cur] < tmp*key[i][cur]){
      Max = tmp;
      prev = i;
      //}
    }
  }
  table[cur][count] = Max * key[prev][cur];
  return table[cur][count];
}

int main() {
  int n, m;
  while (cin >> n >> m && ((n != 0) || (m != 0))) {
    Init(n, m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        cin >> key[i][j];
    for (int i = 0; i < n; i++)
      table[i][0] = memo(i, 0, m - 1, n);
    double max = 0;
    for (int i = 0; i < n; i++)
      if (max < table[i][0])
        max = table[i][0];
    printf("%0.2f\\n", max);
  }

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define EPS 1e-10
using namespace std;
int m, n;
double total;
double dp[110][110];
int Just;
// vector<double> matrix[110];
double matrix[110][110];
/*
double rec(int next,int counter){
  if(dp[next][counter] > 0)return dp[next][counter];
  if(counter  == 0){
    return 1.0;
  }
  double HANMA = 0.0,test=0.0;


  for(int i=0;i<n;i++){

    //HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
    test = rec(i,counter-1)*matrix[next][i];
    if(test > HANMA)HANMA = test;
  }
  dp[Just][counter] = HANMA;
  return HANMA;
}
*/

int main() {

  double In;

  while (cin >> n >> m && n && m) {
    // for(int i=0;i<=n;i++)matrix[i].clear();

    for (int i = m; i >= 0; i--)
      for (int j = 0; j < n; j++)
        dp[j][i] = -10;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        scanf("%lf", &matrix[i][j]);
      }
    }
    for (int i = 0; i < n; i++)
      dp[i][0] = dp[i][1] = 1;

    double ans = -1;
    for (int i = 2; i <= m; i++) {
      for (int j = 0; j < n; j++) {
        ans = -1;
        for (int k = 0; k < n; k++)
          if (ans < dp[k][i - 1] * matrix[j][k])
            ans = dp[k][i - 1] * matrix[j][k];

        dp[j][i] = ans;
      }
    }

    double Fans = 0;
    for (int i = 0; i < n; i++)
      if (Fans < dp[i][m])
        Fans = dp[i][m];
    // cout << endl;

    printf("%.2f\\n", Fans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef pair<double, int> P;
int m, n;
double total;
double dp[110][110];
int Just;
// vector<double> matrix[110];
double matrix[110][110];
double rec(int next, int counter) {
  if (dp[next][counter] > 0)
    return dp[next][counter];
  if (counter == 0) {
    return 1.0;
  }
  double HANMA = 0.0, test = 0.0;

  for (int i = 0; i < n; i++) {

    // HANMA = max(HANMA,rec(i,counter-1)*matrix[next][i]);
    test = rec(i, counter - 1) * matrix[next][i];
    if (test > HANMA)
      HANMA = test;
  }

  dp[Just][counter] = HANMA;
  return HANMA;
}

int main() {

  double In;

  while (cin >> n >> m && n && m) {
    // for(int i=0;i<=n;i++)matrix[i].clear();

    for (int i = m; i >= 0; i--)
      for (int j = 0; j < n; j++)
        dp[j][i] = -10;
    for (int i = 0; i < n; i++)
      dp[i][0] = dp[i][1] = 1;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        // cin >> matrix[i][j];
        scanf("%lf", &matrix[i][j]);
        // matrix[i].push_back(In);
      }
    }

    double ans = -1;

    for (int I = 0; I < n; I++) {
      Just = I;
      double tes = rec(I, m);
      ans = max(ans, dp[Just][m]);
    }

    // for(int i=1;i<=m;i++)cout << dp[0][i] << " ";
    // cout << endl;

    printf("%.2f\\n", ans);
  }
  return 0;
}
Problem p00191 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

#define EPS pow(10, -9)

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    vector<vector<double>> hyou(n, vector<double>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> hyou[i][j];
      }
    }
    vector<vector<double>> nae(m, vector<double>(n, 1.0));
    for (int i = 1; i < m; i++) {
      for (int j = 0; j < n; j++) {
        nae[i][j] = nae[i - 1][0] * hyou[0][j];
        for (int k = 1; k < n; k++) {
          nae[i][j] = max(nae[i][j], nae[i - 1][k] * hyou[k][j]);
        }
      }
    }
    double MAX = 0.0;
    for (int i = 0; i < n; i++) {
      MAX = max(MAX, nae[m - 1][i]);
    }
    MAX += EPS;
    printf("%.2f\\n", MAX);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

vector<vector<double>> hyou(100, vector<double>(100, 0.0));

double seityo(int prev, int type, int limit, double nae) {
  if (limit == 0) {
    return nae;
  } else {
    double MAX = 0.0;
    for (int i = 0; i < type; i++) {
      if (prev != -1) {
        MAX = max(MAX, seityo(i, type, limit - 1, nae * hyou[prev][i]));
      } else {
        MAX = max(MAX, seityo(i, type, limit - 1, nae));
      }
    }
    return MAX;
  }
}

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> hyou[i][j];
      }
    }
    double d = seityo(-1, n, m, 1.0);
    int dd = d * 1000;
    if (dd % 10 >= 5) {
      dd += 10;
    }
    d = dd / 1000.0;
    printf("%.2f\\n", d);
  }
  return 0;
}
Problem p00191 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  cout << setprecision(2);
  cout << setiosflags(ios::fixed);
  int n, m, i, j, k;
  long double M;
  while (cin >> n >> m, n | m) {
    vector<vector<long double>> manure(n, vector<long double>(n)),
        dp(m, vector<long double>(n, 0.0));
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        cin >> manure[i][j];
    for (j = 0; j < n; j++)
      dp[0][j] = 1.0;
    for (i = 1; i < m; i++) {
      for (j = 0; j < n; j++) {
        for (k = 0; k < n; k++) {
          dp[i][j] = max(dp[i][j], dp[i - 1][k] * manure[k][j]);
        }
      }
    }
    M = 0.0;
    for (j = 0; j < n; j++)
      M = max(M, dp[m - 1][j]);
    cout << M << endl;
  }
}

Error: 0

Fixed submission:


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  cout << setprecision(2);
  cout << setiosflags(ios::fixed);
  int n, m, i, j, k;
  long double M;
  while (cin >> n >> m, n | m) {
    vector<vector<long double>> manure(n, vector<long double>(n)),
        dp(m, vector<long double>(n, 0.0));
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        cin >> manure[i][j];
    for (j = 0; j < n; j++)
      dp[0][j] = 1.0;
    for (i = 1; i < m; i++) {
      for (j = 0; j < n; j++) {
        for (k = 0; k < n; k++) {
          dp[i][j] = max(dp[i][j], dp[i - 1][k] * manure[k][j]);
        }
      }
    }
    M = 0.0;
    for (j = 0; j < n; j++)
      M = max(M, dp[n - 1][j]);
    cout << M << endl;
  }
}
Problem p00191 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

const double eps = 1.0e-10;
double eq(double a, double b) { // a==b
  return abs(b - a) < eps;
}
double gt(double a, double b) { // a>b
  return !eq(a, b) && a > b;
}

int main() {
  while (true) {
    int n, m;
    double answer = -1;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    double table[n][n];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> table[i][j];
      }
    }
    double dp[n][m];
    for (int i = 0; i < n; ++i) {
      dp[i][0] = 1.0;
    }
    for (int i = 1; i < m; ++i) {
      for (int j = 0; j < n; ++j) {
        double maximum = -1;
        for (int k = 0; k < n; ++k) {
          double t = table[k][j] * dp[k][i - 1];
          if (gt(t, maximum)) {
            maximum = t;
          }
        }
        dp[j][i] = maximum;
      }
    }

    for (int i = 0; i < n; ++i) {
      if (gt(dp[i][m - 1], answer))
        answer = dp[i][m - 1];
    }
    printf("%.2lf\\n", answer);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

const double eps = 1.0e-10;
double eq(double a, double b) { // a==b
  return abs(b - a) < eps;
}
double gt(double a, double b) { // a>b
  return !eq(a, b) && a > b;
}

int main() {
  while (true) {
    int n, m;
    double answer = -1;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    double table[n][n];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> table[i][j];
      }
    }
    vector<int> colors;
    vector<double> greedy;
    for (int i = 0; i < n; ++i) {
      colors.push_back(i);
      greedy.push_back(1.0);
    }

    for (int k = 0; k < m - 1; ++k) {
      vector<int> next_colors;
      vector<double> next_greedy;
      for (int i = 0; i < colors.size(); ++i) {
        double maximum = -1;
        for (int j = 0; j < n; ++j) {
          double t = greedy[i] * table[colors[i]][j];
          if (gt(t, maximum)) {
            maximum = t;
          }
        }
        for (int j = 0; j < n; ++j) {
          double t = greedy[i] * table[colors[i]][j];
          if (eq(t, maximum)) {
            next_colors.push_back(j);
            next_greedy.push_back(t);
          }
        }
      }
      colors.clear();
      greedy.clear();
      for (int i = 0; i < next_colors.size(); ++i) {
        colors.push_back(next_colors[i]);
        greedy.push_back(next_greedy[i]);
      }
    }

    for (int i = 0; i < greedy.size(); ++i) {
      if (gt(greedy[i], answer))
        answer = greedy[i];
    }
    printf("%.2lf\\n", answer);
  }
  return 0;
}
Problem p00191 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int m, n;
double a[100][100], b[100][100];
double f(int p, int q, double r) {
  int i;
  double mx = 0;
  if (p == m) {
    mx = r;
  } else if (b[p][q] < r) {
    b[p][q] = r;
    for (i = 0; i < n; i++)
      mx = max(mx, f(p + 1, i, r * a[q][i]));
  }
  return mx;
}
int main() {
  int i, j;
  double mx;
  while (cin >> n >> m && n + m) {
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        cin >> a[i][j];
    memset(b, 0, sizeof(b));
    mx = 0;
    for (i = 0; i < n; i++)
      mx = max(mx, f(1, i, 1));
    printf("%.2lf\\n", mx);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int m, n;
double a[100][100], b[100][100];
double f(int p, int q, double r) {
  int i;
  double mx = 0;
  if (p == m) {
    mx = r;
  } else if (b[p][q] < r) {
    b[p][q] = r;
    for (i = 0; i < n; i++)
      mx = max(mx, f(p + 1, i, r * a[q][i]));
    b[p][q] = 0;
  }
  return mx;
}
int main() {
  int i, j;
  double mx;
  while (cin >> n >> m && n + m) {
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        cin >> a[i][j];
    mx = 0;
    for (i = 0; i < n; i++)
      mx = max(mx, f(1, i, 1));
    printf("%.2lf\\n", mx);
  }
  return 0;
}
Problem p00191 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int n, m;
double in[100][100], dp[101][101];

int main(void) {
  while (cin >> n >> m, n | m) {

    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) {
        cin >> in[i][j];
      }
    for (int i = 1; i <= m; ++i)
      fill(dp[i], dp[i] + n, 0);
    fill(dp[0], dp[0] + n, 1);

    for (int i = 1; i < m; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k) {
          // printf("(%lf, %lf, %lf) = (%lf, %lf)\\n", i, j, k, dp[i][j],
          // in[j][k]*dp[i-1][j]);
          dp[i][k] = max(dp[i][k], in[j][k] * dp[i - 1][j]);
          // dp[i][j] = max(dp[i][j], in[k][j] * dp[i-1][j]);
        }
      }
    }
    double Max = -1.0;
    for (int i = 0; i < n; ++i) {
      Max = max(Max, dp[m - 1][i]);
    }
    // for(int i=0; i < m; ++i,printf("\\n"))
    //	for(int j=0; j < n; ++j) printf("%.2lf ", dp[i][j]);

    printf("%.2lf\\n", Max);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

struct Data {
  int idx;
  double point;
};

int n, m;
Data data[100];
double Max;

void search(int prev, double point, int count) {
  if (count == m) {
    if (Max < point) {
      Max = point;
    }
    return;
  }
  search(data[prev].idx, point * data[prev].point, count + 1);
}

int main(void) {
  while (cin >> n >> m, n | m) {
    Max = 0;
    for (int i = 0; i < 100; ++i)
      data[i].point = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        double point;
        cin >> point;
        if (point > data[i].point) {
          data[i].idx = i;
          data[i].point = point;
        }
      }
    for (int i = 0; i < n; ++i)
      search(i, 1.0, 1);
    int tmp = Max * 1000;
    Max = tmp / 1000.0;
    printf("%.2f\\n", Max);
  }
  return 0;
}
Problem p00191 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 1e9

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<vector<double>> bt(n, vector<double>(n));
    vector<vector<double>> dp(m, vector<double>(n, 0.0));

    FOR(i, 0, n) {
      FOR(j, 0, n) { cin >> bt[i][j]; }
      dp[0][i] = 1.0;
    }
    double ans = 0;
    FOR(i, 0, m - 1) {
      FOR(j, 0, n) {
        FOR(k, 0, n) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] * bt[k][j]); }
      }
    }

    FOR(i, 0, n)
    ans = max(ans, dp[m - 1][i]);

    printf("%.2f\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 1e9

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<vector<double>> bt(n, vector<double>(n));
    vector<vector<pair<double, int>>> dp(m);

    FOR(i, 0, n) {
      FOR(j, 0, n) { cin >> bt[i][j]; }
      dp[0].push_back(pair<double, int>(1.0, i));
    }

    double ans = 0.0;
    FOR(i, 0, m - 1) {
      FOR(j, 0, n) {
        FOR(k, 0, dp[i].size()) {
          double g;
          int f;
          tie(g, f) = dp[i][k];
          dp[i + 1].push_back(pair<double, int>(g * bt[f][j], j));
          ans = max(ans, g * bt[f][j]);
        }
      }
    }
    printf("%.2f\\n", ans);
  }
  return 0;
}
Problem p00193 (C++) — buggy submission, verdict: Runtime Error

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

enum { X, Y, DEPTH };
typedef tuple<int, int, int> Node;

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

int m, n;
vector<vector<int>> field;

int bfs(int start_x, int start_y, bool write) {
  int result = 0;
  vector<vector<int>> visited(m, vector<int>(n, 0));
  queue<Node> q;
  q.push(Node(start_x, start_y, 0));
  while (!q.empty()) {
    int x = get<X>(q.front());
    int y = get<Y>(q.front());
    int depth = get<DEPTH>(q.front());
    q.pop();
    if (visited[x][y])
      continue;
    visited[x][y] = 1;
    if (field[x][y] <= depth)
      continue;
    if (write)
      field[x][y] = depth;
    ++result;
    for (int i = 0; i < 6; ++i) {
      int nx = x + dx[y & 1][i];
      int ny = y + dy[y & 1][i];
      if (nx < 0 || m <= nx || ny < 0 || n <= ny)
        continue;
      q.push(Node(nx, ny, depth + 1));
    }
  }
  return result;
}

int main() {
  int s, t;
  int x, y;
  while (cin >> m >> n, m | n) {
    field = vector<vector<int>>(m, vector<int>(n, INT_MAX));
    for (cin >> s; s > 0; --s) {
      cin >> x >> y;
      bfs(x - 1, y - 1, true);
    }
    int answer = 0;
    for (cin >> t; t > 0; --t) {
      cin >> x >> y;
      answer = max(answer, bfs(x - 1, y - 1, false));
    }
    cout << answer << endl;
  }
}

Error: 0

Fixed submission:

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

const int INF = 100000;

class Node {
public:
  int y, x, depth;
  Node(int y, int x, int d) : y(y), x(x), depth(d) {}
};

typedef tuple<int, int> Point;

enum { EVEN, ODD };
enum { Y, X };
const int NEXT[2][6][2] = {
    {
        {0, -1},
        {-1, -1},
        {-1, 0},
        {0, 1},
        {1, -1},
        {1, 0},
    },
    {
        {0, -1},
        {-1, 0},
        {-1, 1},
        {0, 1},
        {1, 0},
        {1, 1},
    },
};

int bfs(vector<vector<int>> &hex, int y, int x, bool write) {
  int h = hex.size(), w = hex[0].size();
  int result = 0;
  queue<Node> q;
  q.push(Node(y, x, 0));
  while (!q.empty()) {
    Node current = q.front();
    q.pop();
    if (hex[current.y][current.x] <= current.depth)
      continue;
    if (write)
      hex[current.y][current.x] = current.depth;
    ++result;
    for (const auto &d : NEXT[y & 1]) {
      int ny = current.y + d[Y];
      int nx = current.x + d[X];
      if (ny < 0 || h <= ny)
        continue;
      if (nx < 0 || w <= nx)
        continue;
      q.push(Node(ny, nx, current.depth + 1));
    }
  }
  return result;
}

int main() {
  int m, n;
  int s, t;
  int x, y;
  while (cin >> m >> n, m | n) {
    vector<vector<int>> hex(n, vector<int>(m, INF));
    for (cin >> s; s > 0; --s) {
      cin >> x >> y;
      bfs(hex, y - 1, x - 1, true);
    }
    int answer = 0;
    for (cin >> t; t > 0; --t) {
      cin >> x >> y;
      answer = max(answer, bfs(hex, y - 1, x - 1, false));
    }
    cout << answer << endl;
  }
}
Problem p00193 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

struct st {
  int x, y, c;
};
int d[100][100], b[100][100], x[11], y[11];
int dx[][6]{{
                0,
                -1,
                0,
                1,
                1,
                1,
            },
            {-1, -1, -1, 0, 1, 0}};
int dy[]{-1, 0, 1, 1, 0, -1};
int main() {
  int m, n, s;
  while (scanf("%d%d", &m, &n), m) {
    scanf("%d", &s);
    rep(i, s) scanf("%d%d", &x[i], &y[i]), x[i]--, y[i]--;
    int t;
    scanf("%d", &t);
    int Max = 0;
    rep(i, t) {
      scanf("%d%d", &x[s], &y[s]);
      x[s]--;
      y[s]--;
      queue<st> que;
      memset(d, -1, sizeof(d));
      rep(j, s + 1) {
        d[x[j]][y[j]] = 0;
        b[x[j]][y[j]] = j;
        que.push({x[j], y[j], j});
      }
      while (!que.empty()) {
        st p = que.front();
        que.pop();
        rep(j, 6) {
          int nx = p.x + dx[!(p.y & 1)][j], ny = p.y + dy[j];
          if (0 <= nx && nx < m && 0 <= ny && ny < n) {
            if (d[nx][ny] == -1) {
              d[nx][ny] = d[p.x][p.y] + 1;
              b[nx][ny] = p.c;
              que.push({nx, ny, p.c});
            } else if (d[nx][ny] == d[p.x][p.y] + 1 && b[nx][ny] != p.c) {
              b[nx][ny] = -1;
              que.push({nx, ny, p.c});
            }
          }
        }
      }
      int cnt = 0;
      rep(i, m) rep(j, n) {
        if (b[i][j] == s)
          cnt++;
      }
      Max = max(Max, cnt);
    }
    printf("%d\\n", Max);
  }
}

Error: MLE

Fixed submission:

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

struct st {
  int x, y, c;
};
int d[100][100], b[100][100], x[11], y[11];
int dx[][6]{{
                0,
                -1,
                0,
                1,
                1,
                1,
            },
            {-1, -1, -1, 0, 1, 0}};
int dy[]{-1, 0, 1, 1, 0, -1};
int main() {
  int m, n, s;
  while (scanf("%d%d", &m, &n), m) {
    scanf("%d", &s);
    rep(i, s) scanf("%d%d", &x[i], &y[i]), x[i]--, y[i]--;
    int t;
    scanf("%d", &t);
    int Max = 0;
    rep(i, t) {
      scanf("%d%d", &x[s], &y[s]);
      x[s]--;
      y[s]--;
      queue<st> que;
      memset(d, -1, sizeof(d));
      rep(j, s + 1) {
        d[x[j]][y[j]] = 0;
        b[x[j]][y[j]] = j;
        que.push({x[j], y[j], j});
      }
      while (!que.empty()) {
        st p = que.front();
        que.pop();
        rep(j, 6) {
          int nx = p.x + dx[!(p.y & 1)][j], ny = p.y + dy[j];
          if (0 <= nx && nx < m && 0 <= ny && ny < n) {
            if (d[nx][ny] == -1) {
              d[nx][ny] = d[p.x][p.y] + 1;
              b[nx][ny] = p.c;
              que.push({nx, ny, p.c});
            } else if (d[nx][ny] == d[p.x][p.y] + 1) {
              b[nx][ny] = -1;
              que.push({nx, ny, p.c});
            }
          }
        }
      }
      int cnt = 0;
      rep(i, m) rep(j, n) {
        if (b[i][j] == s)
          cnt++;
      }
      Max = max(Max, cnt);
    }
    printf("%d\\n", Max);
  }
}