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

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

const int MAX = 50;

int sp2i(string str, int p) {
  string::iterator s, g;
  s = str.begin();
  for (int i = 0; i < p; i++) {
    s = find(s, str.end(), ',');
    s++;
  }
  g = find(s, str.end(), ',');
  string t = string(s, g);
  int c = 0;
  for (int i = 0; i < t.size(); i++) {
    c *= 10;
    c += t[i] - '0';
  }

  return c;
}

int main() {
  int d[MAX][MAX];
  memset(d, 0, sizeof(d));

  vector<string> dt;
  string s;
  while (cin >> s) {
    dt.push_back(s);
  }

  int S = dt.size();
  int N = S / 2;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      d[i - j][j] = sp2i(dt[i], j);
    }
  }

  for (int i = N; i >= 1; i--) {
    for (int j = 0; j < i; j++) {
      d[N - j][N - i + j + 1] = sp2i(dt[S - i], j);
    }
  }

  int dp[MAX][MAX];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = d[0][0];
  for (int i = 1; i <= N; i++) {
    dp[i][0] = dp[i - 1][0] + d[i][0];
    dp[0][i] = dp[0][i - 1] + d[0][i];
  }

  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      dp[i][j] = d[i][j] + max(dp[i - 1][j], dp[i][j - 1]);
    }

  cout << dp[N][N] << endl;

  return 0;
}

Error: MLE

Fixed submission:

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

const int MAX = 50;
int sp2i(string str, int p) {
  string::iterator s, g;
  s = str.begin();
  for (int i = 0; i < p; i++) {
    s = find(s, str.end(), ',');
    s++;
  }
  g = find(s, str.end(), ',');
  string t = string(s, g);
  int c = 0;
  for (int i = 0; i < t.size(); i++) {
    c *= 10;
    c += t[i] - '0';
  }

  return c;
}

int main() {
  int d[MAX][MAX];
  memset(d, 0, sizeof(d));

  vector<string> dt;
  string s;
  bool f = true;
  while (1) {
    cin >> s;
    dt.push_back(s);
    if (f)
      f = false;
    else if (s.size() == 1)
      break;
  }
  int S = dt.size();
  int N = S / 2;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      d[i - j][j] = sp2i(dt[i], j);
    }
  }

  for (int i = N; i >= 1; i--) {
    for (int j = 0; j < i; j++) {
      d[N - j][N - i + j + 1] = sp2i(dt[S - i], j);
    }
  }

  int dp[MAX][MAX];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = d[0][0];
  for (int i = 1; i <= N; i++) {
    dp[i][0] = dp[i - 1][0] + d[i][0];
    dp[0][i] = dp[0][i - 1] + d[0][i];
  }

  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      dp[i][j] = d[i][j] + max(dp[i - 1][j], dp[i][j - 1]);
    }

  cout << dp[N][N] << endl;

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

#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> v;

int main() {
  string s;
  int m = 0;
  while (cin >> s) {
    vector<int> a;
    while (s.size() != 0) {
      if (s.find(",") == -1) {
        a.push_back(stoi(s));
        break;
      } else {
        a.push_back(stoi(s.substr(0, s.find(","))));
        s = s.substr(s.find(",") + 1);
      }
    }
    m = max(m, (int)a.size());
    if (a.size() < m) {
      int p = a.size();
      for (int i = 0; i < m - p; i++)
        a.push_back(0);
      for (int i = p - 1; 0 <= i; i--)
        a[i + (m - p)] = a[i];
      for (int i = 0; i < m - p; i++)
        a[i] = 0;
    }
    while (a.size() < 100)
      a.push_back(0);
    v.push_back(a);
  }
  int memo[110][110] = {0};
  memo[0][0] = v[0][0];
  for (int i = 1; i < v.size(); i++) {
    for (int j = 0; j < v[i].size(); j++) {
      memo[i][j] = max(memo[i][j], v[i][j] + memo[i - 1][j]);
      if (j != 0)
        memo[i][j] = max(memo[i][j], v[i][j] + memo[i - 1][j - 1]);
    }
  }
  int ret = 0;
  for (int i = 0; i < 110; i++) {
    ret = max(ret, memo[v.size() - 1][i]);
  }
  cout << ret << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> v;

int ret = 0;

void f(int n, int x, int y) {
  if (x == v.size() - 1)
    ret = max(ret, n + v[x][y]);
  else {
    for (int i = 0; i <= 1; i++) {
      if (0 <= y + i && y + i < v[x + 1].size())
        f(n + v[x][y], x + 1, y + i);
    }
  }
}

int main() {
  string s;
  int m = 0;
  while (cin >> s) {
    vector<int> a;
    while (s.size() != 0) {
      if (s.find(",") == -1) {
        a.push_back(stoi(s));
        break;
      } else {
        a.push_back(stoi(s.substr(0, s.find(","))));
        s = s.substr(s.find(",") + 1);
      }
    }
    m = max(m, (int)a.size());
    if (a.size() < m) {
      int p = a.size();
      for (int i = 0; i < m - p; i++)
        a.push_back(0);
      for (int i = p - 1; 0 <= i; i--)
        a[i + (m - p)] = a[i];
      for (int i = 0; i < m - p; i++)
        a[i] = 0;
    }
    v.push_back(a);
  }
  f(0, 0, 0);
  cout << ret << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int num[100][100];
int dp[100][100] = {0};
int main() {
  string str;
  int k, c, i, n = 0;
  while (cin >> str) {
    n++;
    k = 0, c = 0, i = 0;
    for (i = 0; i < str.length(); i++) {
      if (str[i] == ',') {
        num[n - 1][c] = k;
        c++;
        k = 0;
      } else {
        k *= 10;
        k += str[i] - '0';
      }
    }
    num[n - 1][c] = k;
  }
  dp[0][0] = num[0][0];
  for (i = 0; i < (n - 1) / 2; i++) {
    for (int j = 0; j <= i; j++) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + num[i + 1][j]);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + num[i + 1][j + 1]);
    }
  }
  for (; i < n - 1; i++) {
    for (int j = 0; j < n - i; j++) {
      if (j > 0)
        dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + num[i + 1][j - 1]);
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + num[i + 1][j]);
    }
  }
  cout << dp[n - 1][0] << endl;
  ;
}

Error: TLE

Fixed submission:

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

vector<vector<int>> vec;
int an = 0;
void dfs(int c, int i, int j, string s) {
  if (i == vec.size() - 1) {
    an = max(an, c);
    return;
  }
  if (j > 0 && i >= vec.size() / 2)
    dfs(c + vec[i + 1][j - 1], i + 1, j - 1,
        s + ',' + to_string(vec[i + 1][j - 1]));
  if (vec[i + 1].size() > j)
    dfs(c + vec[i + 1][j], i + 1, j, s + ',' + to_string(vec[i + 1][j]));
  if (vec[i + 1].size() > j + 1 && i < vec.size() / 2)
    dfs(c + vec[i + 1][j + 1], i + 1, j + 1,
        s + ',' + to_string(vec[i + 1][j + 1]));
}
int main() {
  string str;
  while (cin >> str) {
    vector<int> v;
    int k = 0;
    for (int i = 0; i < str.length(); i++) {
      if (str[i] == ',') {
        v.push_back(k);
        k = 0;
      } else {
        k *= 10;
        k += str[i] - '0';
      }
    }
    v.push_back(k);
    vec.push_back(v);
  }
  dfs(vec[0][0], 0, 0, to_string(vec[0][0]));
  cout << an << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define NONE -1
#define MAX 120

int main(void) {
  VVI G(MAX, VI(MAX, NONE));

  // üÍ
  int cnt = 0;
  while (cin.eof() == false) {
    string input;
    getline(cin, input);

    replace(input.begin(), input.end(), ',', ' ');
    istringstream is(input);

    int n;
    int m = 0;
    while (is >> n) {
      G[cnt][m] = n;
      m++;
    }

    if (m > 0)
      cnt++;
    if (cin.eof())
      break;
  }

  int middle = cnt / 2;
  for (int i = 1; i <= middle; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = middle; k > 0; k--) {
        swap(G[middle + i][k], G[middle + i][k - 1]);
      }
    }
  }

  VVI dp = VVI(MAX, VI(MAX, -1));
  dp[0][0] = G[0][0];
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) {
      if (G[i][j] != NONE) {
        if (G[i + 1][j] != NONE)
          dp[i + 1][j] = max(dp[i + 1][j], G[i + 1][j] + dp[i][j]);
        if (G[i + 1][j + 1] != NONE)
          dp[i + 1][j + 1] = max(dp[i + 1][j + 1], G[i + 1][j + 1] + dp[i][j]);
      }
    }
  }

  int answer = -1;
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++)
      answer = max(answer, dp[i][j]);
  }
  cout << answer << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX 100

int main(void) {
  VVI G(MAX, VI(MAX, 0));

  // üÍ
  int cnt = 0;
  while (cin.eof() == false) {
    string input;
    getline(cin, input);

    replace(input.begin(), input.end(), ',', ' ');
    istringstream is(input);

    int n;
    int m = 0;
    while (is >> n) {
      G[cnt][m] = n;
      m++;
    }

    cnt++;
    if (cin.eof())
      break;
  }

  int middle = cnt / 2;
  for (int i = 1; i <= middle; i++) {
    for (int j = 0; j < i; j++) {
      for (int k = middle; k > 0; k--) {
        swap(G[middle + i][k], G[middle + i][k - 1]);
      }
    }
  }

  VVI dp = VVI(MAX, VI(MAX, 0));
  dp[0][0] = G[0][0];
  for (int i = 0; i < MAX; i++) {
    for (int j = 0; j < MAX; j++) {
      if (dp[i][j] != 0) {
        if (G[i + 1][j] > 0)
          dp[i + 1][j] = max(dp[i + 1][j], G[i + 1][j] + dp[i][j]);
        if (G[i + 1][j + 1] > 0)
          dp[i + 1][j + 1] = max(dp[i + 1][j + 1], G[i + 1][j + 1] + dp[i][j]);
      }
    }
  }

  cout << dp[cnt - 1][middle] << endl;
  return 0;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reep(i, f, n) for (int i = f; i < int(n); ++i)
#define rep(i, n) reep(i, 0, n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main() {
  char str[256];
  while (scanf("%s", str) != EOF) {
    int dp[128] = {0};
    bool increasing = true;
    int num = 0;
    do {
      int tmp[128];
      int tmp_size = 0;

      sscanf(str, "%d,", &tmp[0]);
      ++tmp_size;
      rep(i, strlen(str)) {
        if (str[i] == ',') {
          sscanf(str + i + 1, "%d,", &tmp[tmp_size]);
          ++tmp_size;
        }
      }

      if (tmp_size < num)
        increasing = false;
      num = tmp_size;

      rep(i, num) {
        if (increasing)
          tmp[i] += max(dp[i], i ? dp[i - 1] : 0);
        else
          tmp[i] += max(dp[i], dp[i + 1]);
      }

      rep(i, num) { dp[i] = tmp[i]; }
      if (!increasing && num == 1)
        break;
    } while (scanf("%s", str) != EOF);
    printf("%d\\n", dp[0]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reep(i, f, n) for (int i = f; i < int(n); ++i)
#define rep(i, n) reep(i, 0, n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main() {
  char str[128];
  while (scanf("%s", str) != EOF) {
    int dp[64] = {0};
    bool increasing = true;
    int num = 0;
    do {
      int tmp[64];
      int tmp_size = 0;

      sscanf(str, "%d,", &tmp[0]);
      ++tmp_size;
      rep(i, strlen(str)) {
        if (str[i] == ',') {
          sscanf(str + i + 1, "%d,", &tmp[tmp_size]);
          ++tmp_size;
        }
      }

      if (tmp_size < num)
        increasing = false;
      num = tmp_size;

      rep(i, num) {
        if (increasing)
          tmp[i] += max(dp[i], i ? dp[i - 1] : 0);
        else
          tmp[i] += max(dp[i], dp[i + 1]);
      }

      rep(i, num) { dp[i] = tmp[i]; }
      if (!increasing && num == 1)
        break;
    } while (scanf("%s", str) != EOF);
    printf("%d\\n", dp[0]);
  }
  return 0;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

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

int cnt[100];
int d[100][100];
int dp[100][100];

int main() {
  string s;
  int n;
  for (n = 0; getline(cin, s) && s != ""; n++) {
    s += ',';
    stringstream ss(s);
    char c;
    for (; ss >> d[n][cnt[n]] >> c; cnt[n]++)
      ;
  }
  dp[0][0] = d[0][0];
  for (int i = 1; i < n; i++) {
    rep(j, cnt[i]) {
      if (i <= n / 2) {
        if (!j)
          dp[i][j] = dp[i - 1][j] + d[i][j];
        else
          dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + d[i][j];
      } else {
        if (j == cnt[i - 1] - 1)
          dp[i][j] = dp[i - 1][j] + d[i][j];
        else
          dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + d[i][j];
      }
    }
  }
  printf("%d\\n", dp[n - 1][0]);
}

Error: -6

Fixed submission:

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

int cnt[100];
int d[100][100];
int dp[100][100];

int main() {
  string s;
  int n;
  for (n = 0; getline(cin, s) && s != ""; n++) {
    s += ',';
    stringstream ss(s);
    char c;
    for (; ss >> d[n][cnt[n]] >> c; cnt[n]++)
      ;
  }
  if (n & 1)
    abort();
  dp[0][0] = d[0][0];
  for (int i = 1; i < n; i++) {
    rep(j, cnt[i]) {
      if (i <= n / 2) {
        if (!j)
          dp[i][j] = dp[i - 1][j] + d[i][j];
        else
          dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + d[i][j];
      } else {
        if (j == cnt[i] - 1)
          dp[i][j] = dp[i - 1][j] + d[i][j];
        else
          dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + 1]) + d[i][j];
      }
    }
  }
  printf("%d\\n", dp[n - 1][0]);
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a[100][100] = {};
  int i = 0;
  for (string s; getline(cin, s) && s != "$";) {
    bool flag = false; // 2??±?????????
    int j = 0;
    for (int c = 0; c < s.size(); c++) {
      if (s[c] == ',') {
        flag = false;
        j++;
      } else {
        if (flag) {
          a[i][j] = a[i][j] * 10 + (s[c] - '0');
        } else {
          a[i][j] = s[c] - '0';
          flag = true;
        }
      }
    }
    i++;
  }

  int dp[100][100] = {};
  dp[0][0] = a[0][0];
  int k = 1;
  for (; k <= i / 2; k++) {
    dp[k][0] = dp[k - 1][0] + a[k][0];
    for (int l = 1; l <= k; l++) {
      dp[k][l] = max(dp[k - 1][l - 1], dp[k - 1][l]) + a[k][l];
    }
  }
  for (; k <= i; k++) {
    // cout << k << " " << dp[k - 1][j - k + 2] << endl;
    dp[k][i - k + 1] = dp[k - 1][i - k + 2] + a[k][i - k + 1];
    for (int l = 0; l < i - k + 1; l++) {
      dp[k][l] = max(dp[k - 1][l + 1], dp[k - 1][l]) + a[k][l];
    }
  }
  // for (int x = 0; x < 50; x++) {
  //	for (int y = 0; y < 50; y++) {
  //		cout << a[x][y] << " ";
  //	}
  //	cout << endl;
  // }
  // cout << endl;
  // for (int x = 0; x < 50; x++) {
  //	for (int y = 0; y < 50; y++) {
  //		cout << dp[x][y] << " ";
  //	}
  //	cout << endl;
  // }
  cout << dp[i][0] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a[100][100] = {};
  char c;
  int i = 0, j = 0;
  bool flag = false;
  while (cin >> c) {
    if (c == ',') {
      flag = false;
      j++;
    } else {
      if (flag) {
        i++;
        j = 0;
      }
      flag = true;
      a[i][j] = c - '0';
    }
  }

  int dp[100][100] = {};
  dp[0][0] = a[0][0];
  int k = 1;
  for (; k <= i / 2; k++) {
    dp[k][0] = dp[k - 1][0] + a[k][0];
    for (int l = 1; l <= k; l++) {
      dp[k][l] = max(dp[k - 1][l - 1], dp[k - 1][l]) + a[k][l];
    }
  }
  for (; k <= i; k++) {
    // cout << k << " " << dp[k - 1][j - k + 2] << endl;
    dp[k][i - k + 1] = dp[k - 1][i - k + 2] + a[k][i - k + 1];
    for (int l = 0; l < i - k + 1; l++) {
      dp[k][l] = max(dp[k - 1][l + 1], dp[k - 1][l]) + a[k][l];
    }
  }
  // for (int x = 0; x < 50; x++) {
  //	for (int y = 0; y < 50; y++) {
  //		cout << a[x][y] << " ";
  //	}
  //	cout << endl;
  // }
  // cout << endl;
  // for (int x = 0; x < 50; x++) {
  //	for (int y = 0; y < 50; y++) {
  //		cout << dp[x][y] << " ";
  //	}
  //	cout << endl;
  // }
  cout << dp[i][0] << endl;
  return 0;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string.h>
#include <string>

#define L 110

using namespace std;

int main(void) {
  int i1, i2, i3;
  int c;
  string s;
  string temp;
  int f[L][L];
  int dp[L][L];

  c = 0;
  memset(f, -1, sizeof(f));
  memset(dp, 0, sizeof(dp));

  while (1) {
    cin >> s;

    temp = "";
    s = s + ",";

    for (i1 = 0, i2 = 0; i1 < s.size(); i1++) {
      if (s[i1] == ',') {
        istringstream istr(temp);
        istr >> f[c][i2];
        temp = "";
        i2++;
      } else
        temp += s[i1];
    }
    c++;
    if (c != 1 && count(s.begin(), s.end(), ',') == 1)
      break;
  }

  dp[0][0] = f[0][0];

  for (i1 = 1; i1 <= c / 2; i1++) {
    for (i2 = 0; i2 < c / 2 + 1; i2++) {
      if (i2 == 0)
        dp[i1][i2] = dp[i1 - 1][i2] + f[i1][i2];
      else if (f[i1][i2] != -1) {
        dp[i1][i2] = max(dp[i1 - 1][i2], dp[i1 - 1][i2 - 1]) + f[i1][i2];
      }
    }
  }

  for (i1; i1 < c; i1++) {
    for (i2 = 0; i2 < c / 2 + 1; i2++) {
      if (f[i1][i2] != -1) {
        dp[i1][i2] = max(dp[i1 - 1][i2], dp[i1 - 1][i2 + 1]) + f[i1][i2];
      }
    }
  }

  /*for(i1=0;i1<=c;i1++){
          for(i2=0;i2<c/2+1;i2++){
                  cout<<f[i1][i2]<<" ";
          }
          cout<<endl;
  }*/

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

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <sstream>
#include <string.h>
#include <string>

#define L 110

using namespace std;

int main(void) {
  int i1, i2, i3;
  int c;
  string s;
  string temp;
  int f[L][L];
  int dp[L][L];

  c = 0;
  memset(f, -1, sizeof(f));
  memset(dp, 0, sizeof(dp));

  while (1) {
    cin >> s;

    temp = "";
    s = s + ",";

    for (i1 = 0, i2 = 0; i1 < s.size(); i1++) {
      if (s[i1] == ',') {
        istringstream istr(temp);
        istr >> f[c][i2];
        temp = "";
        i2++;
      } else
        temp += s[i1];
    }
    c++;
    if (c != 1 && s.size() == 2)
      break;
  }

  dp[0][0] = f[0][0];

  for (i1 = 1; i1 <= c / 2; i1++) {
    for (i2 = 0; i2 < c; i2++) {
      if (i2 == 0)
        dp[i1][i2] = dp[i1 - 1][i2] + f[i1][i2];
      else if (f[i1][i2] != -1) {
        dp[i1][i2] = max(dp[i1 - 1][i2], dp[i1 - 1][i2 - 1]) + f[i1][i2];
      }
    }
  }

  for (i1; i1 < c; i1++) {
    for (i2 = 0; i2 < c; i2++) {
      if (f[i1][i2] != -1) {
        dp[i1][i2] = max(dp[i1 - 1][i2], dp[i1 - 1][i2 + 1]) + f[i1][i2];
      }
    }
  }

  /*for(i1=0;i1<=c;i1++){
          for(i2=0;i2<c/2+1;i2++){
                  cout<<f[i1][i2]<<" ";
          }
          cout<<endl;
  }*/

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

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

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#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 << 27
#define all(n) n.begin(), n.end()
#define insert(a, b, c, d) PP(P(a, b), P(c, d))
#define F first
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef long long ll;
typedef unsigned long long ull;
int dx[2][2] = {{0, 1}, {0, -1}};
int dy[2][2] = {{1, 1}, {1, 1}};

int main() {
  vector<int> vec[110];
  string s;
  int inde = 0;
  int mex_size = 0;
  while (cin >> s) {

    for (int i = 0; i < s.length(); i++)
      if (s[i] == ',')
        s[i] = ' ';
    stringstream ss;
    ss << s;
    int cnt = 0;
    while (cnt < (ss.str()).size()) {
      int val;
      if ((ss >> val).fail())
        break;

      vec[inde].push_back(val);
      cnt++;
    }
    mex_size = max(mex_size, (int)vec[inde].size());
    inde++;
  }

  ll dp[inde][mex_size];
  rep(i, inde) rep(j, mex_size) dp[i][j] = -1;
  dp[0][0] = vec[0][0];
  int change = 0;
  rep(i, inde) {

    if (vec[i].size() == mex_size)
      change = 1;

    rep(j, vec[i].size()) {

      for (int k = 0; k < 2; k++) {
        int nx = j + dx[change][k], ny = i + dy[change][k];
        if (!(0 <= nx && nx < vec[ny].size() && 0 <= ny && ny < inde))
          continue;

        dp[ny][nx] = max(dp[ny][nx], dp[i][j] + vec[ny][nx]);
      }
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int vec[110][110];
int ans = 0, st, Index = 0, Index2 = 0;
const int INF = 1 << 29;
void rec(int s, int sum, int counter) {
  if (counter == Index) {
    ans = max(ans, sum);
    return;
  }
  if (vec[s + 1][s] != INF) {
    rec(s, sum + vec[s + 1][s], counter + 1);
  }
  if (vec[s + 1][s + 1] != INF) {
    rec(s + 1, sum + vec[s + 1][s + 1], counter + 1);
  }
}
int main() {
  string s;

  for (int i = 109; i >= 0; i--)
    for (int j = 0; j < 110; j++)
      vec[j][i] = INF;
  while (cin >> s) {
    Index2 = 0;
    st = 0;
    for (int i = 0; i <= s.length(); i++) {
      if (s[i] == ',' || i == s.length()) {
        vec[Index][Index2] = (atoi)(s.substr(st, i - st).c_str());
        st = i + 1;
        Index2++;
      }
    }
    Index++;
  }
  rec(0, vec[0][0], 0);
  cout << ans << endl;
  return 0;
}