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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
using namespace std;
int main() {
  string str;
  int i = 0, j = 0, num;
  int a[250][200];
  int b[250][200];
  while (getline(cin, str)) {
    istringstream is(str);
    j = 0;
    while (is >> num) {
      is.ignore();
      a[i][j] = num, j++;
    }
    i++;
  }
  b[0][0] = a[0][0], i--;
  for (int k = 1; k <= i / 2; k++) {
    for (int l = 0; l <= k; l++) {
      if (!l)
        b[k][l] = a[k][l] + b[k - 1][l];
      else if (k == l)
        b[k][l] = a[k][l] + b[k - 1][l - 1];
      else
        b[k][l] = a[k][l] + max(b[k - 1][l - 1], b[k - 1][l]);
    }
  }
  for (int k = i / 2 + 1; k <= i; k++) {
    for (int l = 0; l <= i - k; l++) {
      b[k][l] = a[k][l] + max(b[k - 1][l], b[k - 1][l + 1]);
    }
  }
  cout << b[i][0] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
using namespace std;
int a[250][200] = {{0}};
int i = 0;
int sum = 0, ans = 0;
int b[250][200] = {{0}};
void check(int x, int y, int z);
int main() {
  string str;
  int j = 0, num;
  while (getline(cin, str)) {
    istringstream is(str);
    j = 0;
    while (is >> num) {
      is.ignore();
      a[i][j] = num;
      j++;
    }
    i++;
  }
  check(0, 0, 0);
  cout << ans << endl;

  return 0;
}
void check(int x, int y, int z) {
  // cout<<x<<y<<z<<endl;
  if (b[x][y] > z) {
    // cout<<"-"<<b[x][y]<<"-"<<z<<endl;
    return;
  }
  b[x][y] = z;
  if (y == i) {
    ans = max(z + a[y][x], ans);
    return;
  }
  if (y == i - 1)
    check(0, y + 1, z + a[y][x]);
  else if (y < i / 2) {
    check(x, y + 1, z + a[y][x]);
    check(x + 1, y + 1, z + a[y][x]);
  } else if (y >= i / 2) {
    check(x, y + 1, z + a[y][x]);
    check(x - 1, y + 1, z + a[y][x]);
  }
  return;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <sstream>

using namespace std;

int d[50][100], dp[50][100];

int main() {
  string str;
  int l = 0;
  memset(d, -1, sizeof(d));
  memset(dp, -1, sizeof(d));
  while (cin >> str) {
    replace(str.begin(), str.end(), ',', ' ');
    stringstream sstr(str);
    int i = 0;
    while (sstr >> d[i++][l])
      ;
    l++;
  }
  dp[0][0] = d[0][0];
  for (int i = 1; i < l; i++) {
    for (int j = 0; j != 50 && d[j][i] != -1; j++) {
      if ((l / 2) < i) {
        dp[j][i] = max(dp[j][i - 1], j < 49 ? dp[j + 1][i - 1] : -1);
      } else {
        dp[j][i] = max(dp[j][i - 1], j > 0 ? dp[j - 1][i - 1] : -1);
      }
      dp[j][i] += d[j][i];
    }
  }
  cout << dp[0][l - 1] << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <sstream>

using namespace std;

int d[50][100], dp[50][100];

int main() {
  string str;
  int l = 0;
  memset(d, -1, sizeof(d));
  memset(dp, -1, sizeof(d));
  while (cin >> str) {
    replace(str.begin(), str.end(), ',', ' ');
    stringstream sstr(str);
    int i = 0;
    while (sstr >> d[i++][l])
      ;
    l++;
  }
  dp[0][0] = d[0][0];
  for (int i = 1; i < l; i++) {
    for (int j = 0; d[j][i] != -1; j++) {
      if ((l / 2) < i) {
        dp[j][i] = max(dp[j][i - 1], j < 50 ? dp[j + 1][i - 1] : -1);
      } else {
        dp[j][i] = max(dp[j][i - 1], j >= 0 ? dp[j - 1][i - 1] : -1);
      }
      dp[j][i] += d[j][i];
    }
  }
  cout << dp[0][l - 1] << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, j) for (int i = 0; i < j; i++)
#define f(i, k, j) for (int i = k; i < j; i++)
#define P pair<int, int>
const int INF = (1 << 26);
const int MAX_N = 102;

void disp();
int dp[MAX_N][MAX_N], n;

int main() {
  string s;
  char ch;
  int t[MAX_N][MAX_N];

  for (n = 0; cin >> s; n++) {
    stringstream ss(s);
    for (int j = 0;; j++) {
      ss >> t[n][j];
      if (!(ss >> ch))
        break;
    }
  }

  memset(dp, -1, sizeof(dp));
  dp[0][0] = t[0][0];

  int i = 0;
  for (; i < n / 2; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + t[i + 1][j]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + t[i + 1][j + 1]);
    }
  }
  for (; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      dp[i][j] = max(dp[i - 1][j] + t[i][j], dp[i - 1][j + 1] + t[i][j]);
    }
  }

  cout << dp[n - 1][0] << endl;
  return 0;
}

void disp() {
  rep(i, n) {
    rep(j, 15) { cout << dp[i][j] << ", "; }
    cout << endl;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
#define MAX_N 50

int dp[2][MAX_N + 1], m = 0;

void resetDp();
void setdp();
void next();
void up(int cnt);
void down(int cnt);
void dispAns();

int main() {
  resetDp();
  cin >> dp[0][0];
  setdp();
  dispAns();
  return 0;
}

void resetDp() {
  for (int i = 0; i <= MAX_N; i++) {
    dp[0][i] = 0;
    dp[1][i] = 0;
  }
}

void setdp() {
  string tmp;
  while (true) {
    cin >> tmp;
    int cnt = 0;
    for (int i = 0; i < tmp.size(); i++) {
      if (tmp[i] != ',') {
        dp[1][cnt] = tmp[i] - '0';
        cnt++;
      }
    }
    if (m < cnt) {
      m = cnt;
      up(cnt);
    } else if (m > cnt) {
      down(cnt);
      if (cnt == 1)
        break;
    }
    next();
  }
}

void next() {
  for (int i = 0; i <= MAX_N; i++)
    dp[0][i] = dp[1][i];
}

void up(int cnt) {
  for (int i = 0; i < cnt; i++) {
    if (i - 1 < 0)
      dp[1][i] += dp[0][i];
    else
      dp[1][i] += max(dp[0][i], dp[0][i - 1]);
  }
}

void down(int cnt) {
  for (int i = 0; i < cnt; i++) {
    dp[1][i] += max(dp[0][i], dp[0][i + 1]);
  }
}

void dispAns() {
  int max = -1;
  for (int i = 0; i <= MAX_N; i++) {
    if (max < dp[1][i])
      max = dp[1][i];
  }
  cout << max << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <sstream>
using namespace std;

int main(void) {
  int n, t[102][102];
  char ch;
  string s;

  for (n = 0; cin >> s; n++) {
    stringstream ss(s);
    for (int j = 0;; j++) {
      ss >> t[n][j];
      if (!(ss >> ch))
        break;
    }
  }

  int dp[102][102];
  memset(dp, -1, sizeof(dp));

  // ツ陳可崢づ個δ可イツδ督づ慊づ繰ツづィツ陛板つキ
  dp[0][0] = t[0][0];
  for (int i = 0; i < n / 2; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + t[i + 1][j]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + t[i + 1][j + 1]);
    }
  }

  // ツ陳可崢づ個δ可イツδ督づ個可コツつゥツづァツ催古」ツづ慊づ繰ツづィツ陛板つキ
  for (int i = n / 2 + 1; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      dp[i][j] = max(dp[i - 1][j] + t[i][j], dp[i - 1][j + 1] + t[i][j]);
    }
  }

  cout << dp[n - 1][0] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <sstream>
using namespace std;

int main(void) {
  int n, t[52][52];
  char ch;
  string s;

  for (n = 0; cin >> s; n++) {
    stringstream ss(s);
    for (int j = 0;; j++) {
      ss >> t[n][j];
      if (!(ss >> ch))
        break;
    }
  }

  int dp[52][52];
  memset(dp, -1, sizeof(dp));

  // ツ陳可崢づ個δ可イツδ督づ慊づ繰ツづィツ陛板つキ
  dp[0][0] = t[0][0];
  for (int i = 0; i < n / 2; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + t[i + 1][j]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + t[i + 1][j + 1]);
    }
  }

  // ツ陳可崢づ個δ可イツδ督づ個可コツつゥツづァツ催古」ツづ慊づ繰ツづィツ陛板つキ
  for (int i = n / 2 + 1; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      dp[i][j] = max(dp[i - 1][j] + t[i][j], dp[i - 1][j + 1] + t[i][j]);
    }
  }

  cout << dp[n - 1][0] << endl;

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

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string InputString;
  int Num, Count = 0;
  int Value[128][128];
  int CalcTable[128][128];

  while (getline(cin, InputString)) {
    istringstream is(InputString);
    for (int i = 0; is >> Num; ++i) {
      is.ignore();
      Value[Count][i] = Num;
    }
    Count++;
  }

  CalcTable[0][0] = Value[0][0];
  Count--;

  for (int i = 1; i <= Count / 2; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (!j)
        CalcTable[i][j] = Value[i][j] + CalcTable[i - 1][j];
      else if (j == i)
        CalcTable[i][j] = Value[i][j] + CalcTable[i - 1][j - 1];
      else
        CalcTable[i][j] =
            Value[i][j] + max(CalcTable[i - 1][j - 1], CalcTable[i - 1][j]);
    }
  }

  for (int i = Count / 2 + 1; i <= Count; ++i) {
    for (int j = 0; j <= Count - i; ++j) {
      CalcTable[i][j] =
          Value[i][j] + max(CalcTable[i - 1][j], CalcTable[i - 1][j + 1]);
    }
  }

  cout << CalcTable[Count][0] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int val[300][200];
  int dp[300][200];
  fill(val[0], val[0] + 40000, 0);
  fill(dp[0], dp[0] + 40000, 0);
  int endFlag = false;
  int cnt = 0;
  while (true) {
    char str[300];
    cin >> str;
    int len = strlen(str);
    val[cnt][1] = str[0] - '0';
    for (int i = 2; i < len; i += 2)
      val[cnt][i / 2 + 1] = str[i] - '0';
    cnt++;
    if (len == 1) {
      if (endFlag)
        break;
      endFlag = true;
    }
  }

  dp[0][1] = val[0][1];
  for (int i = 1; i < (cnt + 1) / 2; i++) {
    for (int j = 1; j <= i + 1; j++) {
      dp[i][j] = val[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j]);
    }
  }
  for (int i = (cnt + 1) / 2; i < cnt; i++) {
    for (int j = 1; j <= cnt - i; j++) {
      dp[i][j] = val[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]);
    }
  }
  cout << dp[cnt - 1][1] << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int N = 101;
int dp[N][N], a[N][N];
vector<int> split(string s) {
  vector<int> res;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] == ',')
      s[i] = ' ';
  istringstream is(s);
  int t;
  while (is >> t)
    res.push_back(t);
  return res;
}
int main() {
  string in;
  int pn = 0;
  int n = 0, m = 0;
  while (cin >> in) {
    vector<int> t = split(in);
    for (int i = 0; i < t.size(); ++i)
      a[n][i] = t[i];
    n++;
    m = max(m, (int)t.size());
  }
  dp[0][0] = a[0][0];
  for (int i = 1; i < m; ++i)
    for (int j = 0; j < m; ++j)
      dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j]) + a[i][j];
  for (int i = m; i < n; ++i)
    for (int j = 0; j < m; ++j)
      dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + a[i][j];
  cout << dp[n - 1][0] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const int N = 101;
int dp[N][N];
vector<int> split(string s) {
  vector<int> res;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] == ',')
      s[i] = ' ';
  istringstream is(s);
  int t;
  while (is >> t)
    res.push_back(t);
  return res;
}
int main() {
  string in;
  int k = 0;
  int pn = 0;
  while (cin >> in) {
    vector<int> a = split(in);
    int n = a.size();
    if (n == 50)
      return 1;
    if (k == 0) {
      dp[0][0] = a[0];
    } else {
      if (n > pn) {
        dp[k][0] = dp[k - 1][0] + a[0];
        for (int i = 1; i < n; ++i)
          dp[k][i] = max(dp[k - 1][i - 1], dp[k - 1][i]) + a[i];
      } else {
        for (int i = 0; i < n - 1; ++i)
          dp[k][i] = max(dp[k - 1][i], dp[k - 1][i + 1]) + a[i];
        dp[k][n - 1] = dp[k - 1][n - 1] + a[n - 1];
      }
    }
    pn = n;
    k++;
  }
  cout << dp[k - 1][0] << endl;
  return 0;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stack>
#include <stdio.h>

using namespace std;

int main() {

  int dp[100][200], row = 0, tmp, index, width[100], max_width = 0,
                    max_width_row;
  char buf[200];

  while (scanf("%s", buf) != EOF) {
    index = tmp = 0;
    for (int i = 0; buf[i] != '\\0'; i++) {
      if (buf[i] >= '0' && buf[i] <= '9') {
        tmp = tmp * 10 + (buf[i] - '0');
        if (buf[i + 1] == '\\0') {
          dp[row][index++] = tmp;
        }
      } else {
        dp[row][index++] = tmp;
        tmp = 0;
      }
    }
    if (max_width < index) {
      max_width = index;
      max_width_row = row;
    }

    width[row] = index;
    row++;
  }

  for (int i = 1; i <= max_width_row; i++) {
    for (int k = 0; k < width[i]; k++) {
      if (k == 0) {
        dp[i][0] += dp[i - 1][0];
      } else if (k == width[i] - 1) {
        dp[i][k] += dp[i - 1][width[i - 1] - 1];
      } else {
        dp[i][k] += max(dp[i - 1][k - 1], dp[i - 1][k]);
      }
    }
  }

  for (int i = max_width_row + 1; i < row; i++) {
    for (int k = 0; k < width[i]; k++) {
      dp[i][k] += max(dp[i - 1][k], dp[i - 1][k + 1]);
    }
  }

  printf("%d\\n", dp[row - 1][0]);

  return 0;
}

Error: 0

Fixed submission:

#include <math.h>
#include <stack>
#include <stdio.h>

using namespace std;

int main() {

  int dp[100][1000], row = 0, tmp, index, width[100], max_width = 0,
                     max_width_row;
  char buf[55];

  while (scanf("%s", buf) != EOF) {
    index = tmp = 0;
    for (int i = 0; buf[i] != '\\0'; i++) {
      if (buf[i] >= '0' && buf[i] <= '9') {
        tmp = tmp * 10 + (buf[i] - '0');
        if (buf[i + 1] == '\\0') {
          dp[row][index++] = tmp;
        }
      } else {
        dp[row][index++] = tmp;
        tmp = 0;
      }
    }
    if (max_width < index) {
      max_width = index;
      max_width_row = row;
    }

    width[row] = index;
    row++;
  }

  for (int i = 1; i <= max_width_row; i++) {
    for (int k = 0; k < width[i]; k++) {
      if (k == 0) {
        dp[i][0] += dp[i - 1][0];
      } else if (k == width[i] - 1) {
        dp[i][k] += dp[i - 1][width[i - 1] - 1];
      } else {
        dp[i][k] += max(dp[i - 1][k - 1], dp[i - 1][k]);
      }
    }
  }

  for (int i = max_width_row + 1; i < row; i++) {
    for (int k = 0; k < width[i]; k++) {
      dp[i][k] += max(dp[i - 1][k], dp[i - 1][k + 1]);
    }
  }

  printf("%d\\n", dp[row - 1][0]);

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

#include <bits/stdc++.h>
using namespace std;
int data[150][150];
int memo[200][200];
int i;
int solve(int idx, int idxy) {
  if (idx == i + 1) {
    return 0;
  }
  if (data[idx][idxy] == -1) {
    return 0;
  }
  if (memo[idx][idxy] != -1) {
    return memo[idx][idxy];
  }
  int ret = data[idx][idxy];
  if (idx < i / 2) {
    ret = max(ret + solve(idx + 1, idxy), ret + solve(idx + 1, idxy + 1));
  } else {
    ret = max(ret + solve(idx + 1, idxy), ret + solve(idx + 1, idxy - 1));
  }
  return memo[idx][idxy] = ret;
}

int main() {
  int w, j;
  i = j = 0;
  memset(data, -1, sizeof(data));
  while (cin >> w) {
    data[i][j] = w;
    j++;
    char c = cin.get();
    if (c == '\\n') {
      i++;
      j = 0;
    }
  }
  memset(memo, -1, sizeof(memo));
  cout << solve(0, 0) << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int data[150][150];
int i;
int solve(int idx, int idxy) {
  if (idx == i + 1) {
    return 0;
  }
  if (data[idx][idxy] == -1) {
    return 0;
  }
  int ret = data[idx][idxy];
  if (idx < i / 2) {
    ret = max(ret + solve(idx + 1, idxy), ret + solve(idx + 1, idxy + 1));
  } else {
    ret = max(ret + solve(idx + 1, idxy), ret + solve(idx + 1, idxy - 1));
  }
  return ret;
}

int main() {
  int w, j;
  i = j = 0;
  memset(data, -1, sizeof(data));
  while (cin >> w) {
    data[i][j] = w;
    j++;
    char c = cin.get();
    if (c == '\\n') {
      i++;
      j = 0;
    }
  }
  cout << i << endl;
  cout << solve(0, 0) << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
main() {
  string s;
  int d[102][102] = {}, r = 0;
  while (getline(cin, s)) {
    int c = 1, digit = 0;
    string t;
    for (int i = 0; i < s.size(); ++i)
      if (s[i] == ',')
        d[r][c++] = atoi(t.c_str()), t = "";
      else
        t += s[i];
    d[r++][c] = atoi(t.c_str());
  }
  int m[102][102] = {};
  m[0][1] = d[0][1];
  int n = r / 2 + 1;
  for (int i = 1; i < n; i++)
    for (int j = 1; j < 102; j++)
      m[i][j] = d[i][j] + max(m[i - 1][j - 1], m[i - 1][j]);
  for (int i = n; i < r; i++)
    for (int j = 1; j < 101; j++)
      m[i][j] = d[i][j] + max(m[i - 1][j], m[i - 1][j + 1]);
  cout << m[r - 1][1] << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
  string s[100];
  int p = 0;
  while (cin >> s[p++]) {
  }
  p--;
  for (int i = 0; i < p; i++) {
    if (s[i].size() == p)
      continue;
    int t = (p - s[i].size()) / 2;
    for (int j = 0; j < t; j++) {
      s[i] += ' ';
      s[i] = ' ' + s[i];
    }
  }
  for (int i = 0; i < p; i++) { // cout<<s[i]<<endl;
    for (int j = 0; j < p; j++) {
      a[i][j] = -1;
      if (isdigit(s[i][j]))
        a[i][j] = s[i][j] - '0';
    }
  }
  for (int i = 0; i <= p; i++) {
    int t[100] = {};
    for (int j = 0; j < p; j++) {
      if (a[i][j]) {
        if (j < p - 1) {
          if (a[i + 1][j + 1] >= 0)
            t[j + 1] = max(t[j + 1], a[i + 1][j + 1] + a[i][j]);
        }
        if (j) {
          if (a[i + 1][j - 1] >= 0)
            t[j - 1] = max(t[j - 1], a[i + 1][j - 1] + a[i][j]);
        }
      }
    }
    for (int j = 0; j < 100; j++)
      a[i + 1][j] = t[j];
  }
  // for(int i=0;i<p;i++){for(int
  // j=0;j<p;j++)if(a[i][j])cout<<a[i][j];cout<<endl;}
  for (int i = 0; i < p; i++) {
    if (a[p - 1][i])
      cout << a[p - 1][i] << endl;
    else if (i == p - 1)
      cout << 0 << endl;
  }
}
Problem p00090 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, ans;
double x[101], y[101], a[101][101];
int main() {
  while (cin >> n, n) {
    ans = 0;
    r(i, n) scanf("%lf,%lf", &x[i], &y[i]);
    r(i, 1000) r(j, 1000) {
      int a = 0;
      r(k, n) if ((x[k] - (double)i / 10) * (x[k] - (double)i / 10) +
                      (y[k] - (double)j / 10) * (y[k] - (double)j / 10) <=
                  1) a++;
      ans = max(a, ans);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, ans;
double x[101], y[101], a[101][101];
int vis[101], cur[101];
void dfs(int x, int p) {
  if (vis[x] <= cur[x])
    return;
  cur[x] = p;
  for (int i = x - 1; i >= 0; i--)
    if (a[x][i] <= 2)
      dfs(i, p + 1);
  ans = max(ans, p);
}
int main() {
  while (cin >> n, n) {
    r(i, n) scanf("%lf,%lf", &x[i], &y[i]);
    memset(a, 0, sizeof(a));
    r(i, n) for (int j = i + 1; j < n; j++) a[i][j] = a[j][i] =
        sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
    ans = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = n - 1; i >= 0; i--) {
      if (i == n - 1)
        r(i, n) cur[i] = 1;
      else
        r(i, n) cur[i] = 0;
      dfs(i, 1);
      r(i, n) vis[i] = max(vis[i], cur[i]);
    }
    cout << ans << endl;
  }
}
Problem p00090 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, ans;
double x[101], y[101], a[101][101];
int main() {
  while (cin >> n, n) {
    ans = 0;
    r(i, n) scanf("%lf,%lf", &x[i], &y[i]);
    r(i, 1000) r(j, 1000) {
      int a = 0;
      r(k, n) if ((x[k] - (double)i / 100) * (x[k] - (double)i / 100) +
                      (y[k] - (double)j / 100) * (y[k] - (double)j / 100) <=
                  1) a++;
      ans = max(a, ans);
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n, ans;
double x[101], y[101], a[101][101];
int main() {
  while (cin >> n, n) {
    ans = 0;
    r(i, n) scanf("%lf,%lf", &x[i], &y[i]);
    r(i, 10000) r(j, 10000) {
      int a = 0;
      r(k, n) if ((x[k] - (double)i / 10) * (x[k] - (double)i / 10) +
                      (y[k] - (double)j / 10) * (y[k] - (double)j / 10) <=
                  1) a++;
      ans = max(a, ans);
    }
    cout << ans << endl;
  }
}
Problem p00090 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

double X[100], Y[100];

double sq(double x) { return x * x; }

double sqsum(double a, double b) { return sq(a) + sq(b); }

int main() {
  int n;
  while (cin >> n, n) {
    char c;
    for (int i = 0; i < n; ++i) {
      cin >> X[i] >> c >> Y[i];
    }
    int ans = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (sqsum(X[i] - X[j], Y[i] - Y[j]) > 4.0)
          continue;
        double cx = (X[i] + X[j]) / 2.0;
        double cy = (Y[i] + Y[j]) / 2.0;
        double w = hypot(X[i] - X[j], Y[i] - Y[j]);
        double h = sqrt(1.0 - sq(w / 2.0));
        double dx = (Y[i] - Y[j]) * h / w;
        double dy = (X[j] - X[i]) * h / w;
        int cnt1 = 2, cnt2 = 2;
        for (int k = 0; k < n; ++k) {
          if (k == i || k == j)
            continue;
          if (sqsum(cx + dx - X[k], cy + dy - Y[k]) <= 1.0)
            cnt1++;
          if (sqsum(cx - dx - X[k], cy - dy - Y[k]) <= 1.0)
            cnt2++;
        }
        ans = max(ans, max(cnt1, cnt2));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <complex>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef complex<double> P;

int n;
bool used[100];
vector<complex<double>> seals(100);

bool overlap(complex<double> &a, complex<double> &b, double dist) {
  if (norm(a - b) <= dist)
    return true;
  return false;
}

int solve(complex<double> &i1, complex<double> &i2) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      bool ok = true;
      for (int j = 0; j < n; ++j) {
        if (used[j] && !overlap(seals[i], seals[j], 4.0) &&
            !overlap(seals[i], i1, 1.0) && !overlap(seals[i], i2, 1.0)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        used[i] = true;
        ret = max(ret, 1 + solve(i1, i2));
        used[i] = false;
      }
    }
  }
  return ret;
}

int main() {
  while (cin >> n, n) {
    memset(used, 0, sizeof used);
    seals.clear();
    double x, y;
    char c;
    for (int i = 0; i < n; ++i) {
      cin >> x >> c >> y;
      seals[i].real(x);
      seals[i].imag(y);
    }
    int ret = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (overlap(seals[i], seals[j], 4.0)) {
          ret = max(ret, 2);
          complex<double> m = (seals[i] + seals[j]) / 4.0;
          double k = sqrt(1.0 - norm(m - seals[j])) / sqrt(norm(m - seals[j]));
          double dx = (m.imag() - seals[j].imag()) * k;
          double dy = (seals[j].real() - m.real()) * k;
          complex<double> intersect1(m.real() + dx, m.imag() + dy);
          complex<double> intersect2(m.real() - dx, m.imag() - dy);
          used[i] = used[j] = true;
          ret = max(ret, 2 + solve(intersect1, intersect2));
          used[i] = used[j] = false;
        }
      }
    }
    cout << ret << endl;
  }
  return 0;
}