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

#include <stdio.h>
int main() {
  int m, fand, year, n, ri, com;
  int max, tmp, in;
  double nen;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d%d", &fand, &year, &n);
    max = 0;
    while (n--) {
      tmp = fand;
      in = 0;
      scanf("%d%lf%d", &ri, &nen, &com);
      for (int i = 0; i < year; i++) {
        if (ri == 1)
          tmp += (int)((double)tmp * nen);
        else
          in += (int)((double)tmp * nen);
        tmp -= com;
      }
      tmp += in;
      // printf("tmp%d:%d\\n",n,tmp);
      // printf("in%d:%d\\n",n,in);
      if (max < tmp)
        max = tmp;
    }
    printf("%d\\n", max);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int m, fand, year, n, ri, nen, com;
  int max, tmp, in = 0;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d%d", &fand, &year, &n);
    max = 0;
    tmp = fand;
    while (n--) {
      scanf("%d%lf%d", &ri, &nen, &com);
      while (year--) {
        if (ri == 1)
          tmp += (int)((double)tmp * nen);
        else
          in += (int)((double)tmp * nen);
        tmp -= com;
      }
      tmp += in;
      if (max < tmp)
        max = tmp;
    }
    printf("%d\\n", max);
  }
  return 0;
}
Problem p00717 (C++) — buggy submission, verdict: Runtime Error

#include <assert.h>
#include <iostream>

using namespace std;

void hoge(int N) {

  int M;
  cin >> M;
  int X[M], Y[M];
  for (int i = 0; i < M; i++)
    cin >> X[i] >> Y[i];
  for (int n = 0; n < N; n++) {
    int m;
    cin >> m;
    int x[m], y[m];
    for (int i = 0; i < m; i++)
      cin >> x[i] >> y[i];
    if (m != M)
      continue;
    bool okok = false;
    for (int k = 0; k < 4; k++) {
      for (int i = 0; i < M; i++) {
        swap(X[i], Y[i]);
        X[i] = -X[i];
      }
      bool ok = true;
      for (int i = 0; i + 1 < m; i++) {
        ok &= (x[i + 1] - x[i] == X[i + 1] - X[i]);
        ok &= (y[i + 1] - y[i] == Y[i + 1] - Y[i]);
      }
      bool rev = true;
      for (int i = 0, j = m - 1; i + 1 < m, j > 0; i++, j--) {
        rev &= (x[i + 1] - x[i] == X[j - 1] - X[j]);
        rev &= (y[i + 1] - y[i] == Y[j - 1] - Y[j]);
      }
      okok |= (ok || rev);
    }
    if (okok) {
      cout << n + 1 << endl;
    }
  }
}

int main() {

  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    hoge(N);
    cout << "+++++" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <assert.h>
#include <iostream>

using namespace std;

void hoge(int N) {

  int M;
  cin >> M;
  int X[M], Y[M];
  for (int i = 0; i < M; i++)
    cin >> X[i] >> Y[i];
  for (int n = 0; n < N; n++) {
    int m;
    cin >> m;
    assert(m == M);
    int x[m], y[m];
    for (int i = 0; i < m; i++)
      cin >> x[i] >> y[i];
    bool okok = false;
    for (int k = 0; k < 4; k++) {
      for (int i = 0; i < M; i++) {
        swap(X[i], Y[i]);
        X[i] = -X[i];
      }
      bool ok = true;
      for (int i = 0; i + 1 < m; i++) {
        ok &= (x[i + 1] - x[i] == X[i + 1] - X[i]);
        ok &= (y[i + 1] - y[i] == Y[i + 1] - Y[i]);
      }
      bool rev = true;
      for (int i = 0, j = m - 1; i + 1 < m, j > 0; i++, j--) {
        rev &= (x[i + 1] - x[i] == X[j - 1] - X[j]);
        rev &= (y[i + 1] - y[i] == Y[j - 1] - Y[j]);
      }
      okok |= (ok || rev);
    }
    if (okok) {
      cout << n + 1 << endl;
    }
  }
}

int main() {

  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    hoge(N);
    cout << "+++++" << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <vector>
#define X first
#define Y second
using namespace std;
int n, m, k;
vector<pair<int, int>> v, s;

bool IsSame() {
  bool ok = true;
  int sx = v[0].X - s[0].X, sy = v[0].Y - s[0].Y;
  for (int i = 1; i < m; i++) {
    if (v[i].X - s[i].X == sx && v[i].Y - s[i].Y == sy) {
    } else
      ok = false;
  }
  if (ok)
    return true;

  ok = true;
  sx = v[0].X - s[m - 1].X, sy = v[0].Y - s[m - 1].Y;
  for (int i = 1; i < m; i++) {
    if (v[i].X - s[m - 1 - i].X == sx && v[i].Y - s[m - 1 - i].Y == sy) {
    } else
      ok = false;
  }
  if (ok)
    return true;

  return false;
}

bool Solve() {
  cin >> m;
  s.clear();
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s.push_back(make_pair(x, y));
  }
  if (m != v.size())
    return false;
  if (IsSame())
    return true;
  for (int i = 0; i < m; i++)
    s[i].X = -s[i].X, s[i].Y = -s[i].Y;
  if (IsSame())
    return true;
  for (int i = 0; i < m; i++) {
    int t = s[i].X;
    s[i].X = s[i].Y;
    s[i].Y = -t;
  }
  if (IsSame())
    return true;
  for (int i = 0; i < m; i++)
    s[i].X = -s[i].X, s[i].Y = -s[i].Y;
  if (IsSame())
    return true;

  return false;
}

int main() {
  while (cin >> n && n > 0) {
    cin >> k;
    v.clear();
    for (int i = 0; i < k; i++) {
      int x, y;
      cin >> x >> y;
      v.push_back(make_pair(x, y));
    }
    for (int i = 1; i <= n; i++) {
      if (Solve())
        cout << i << endl;
    }
    cout << "+++++" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define X first
#define Y second
using namespace std;
int n, m;
vector<pair<int, int>> v, s;

bool IsSame() {
  bool ok = true;
  int sx = v[0].X - s[0].X, sy = v[0].Y - s[0].Y;
  for (int i = 1; i < m; i++) {
    if (v[i].X - s[i].X == sx && v[i].Y - s[i].Y == sy) {
    } else
      ok = false;
  }
  if (ok)
    return true;

  ok = true;
  sx = v[0].X - s[m - 1].X, sy = v[0].Y - s[m - 1].Y;
  for (int i = 1; i < m; i++) {
    if (v[i].X - s[m - 1 - i].X == sx && v[i].Y - s[m - 1 - i].Y == sy) {
    } else
      ok = false;
  }
  if (ok)
    return true;

  return false;
}

bool Solve() {
  cin >> m;
  if (m != v.size())
    return false;
  s.clear();
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s.push_back(make_pair(x, y));
  }
  if (IsSame())
    return true;
  for (int i = 0; i < m; i++)
    s[i].X = -s[i].X, s[i].Y = -s[i].Y;
  if (IsSame())
    return true;
  for (int i = 0; i < m; i++) {
    int t = s[i].X;
    s[i].X = s[i].Y;
    s[i].Y = -t;
  }
  if (IsSame())
    return true;
  for (int i = 0; i < m; i++)
    s[i].X = -s[i].X, s[i].Y = -s[i].Y;
  if (IsSame())
    return true;

  return false;
}

int main() {
  while (cin >> n && n) {
    cin >> m;
    while (m--) {
      int x, y;
      cin >> x >> y;
      v.clear();
      v.push_back(make_pair(x, y));
    }
    for (int i = 1; i <= n; i++) {
      if (Solve())
        cout << i << endl;
    }
    cout << "+++++" << endl;
  }
  return 0;
}
Problem p00717 (C++) — buggy submission, verdict: Runtime Error

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

vector<int> x[51], y[51];

bool judge(int a) {
  if (x[0].size() != x[a].size())
    return false;
  rep(i, 4) {
    swap(x[a], y[a]);
    for (int &k : x[a])
      k = -k;
    int d1 = x[a][0], d2 = y[a][0];
    for (int &k : x[a])
      k -= d1;
    for (int &k : y[a])
      k -= d2;
    bool ok = true;
    rep(i, x[0].size()) {
      if (x[0][i] != x[a][i] || y[0][i] != y[a][i]) {
        ok = false;
        break;
      }
    }
    if (ok)
      return true;
  }
  return false;
}
int main() {
  int n;
  while (scanf("%d", &n), n) {
    rep(i, n + 1) {
      int m;
      scanf("%d", &m);
      x[i] = y[i] = vector<int>(m);
      rep(j, m) scanf("%d%d", &x[i][j], &y[i][j]);
    }
    judge(0);
    for (int i = 1; i <= n; i++) {
      if (judge(i)) {
        printf("%d\\n", i);
        continue;
      }
      reverse(x[i].begin(), x[i].end());
      reverse(y[i].begin(), y[i].end());
      if (judge(i)) {
        printf("%d\\n", i);
      }
    }
    puts("+++++");
  }
}

Error: WA

Fixed submission:

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

vector<int> x[51], y[10];

bool judge(int a) {
  rep(i, 4) {
    int d1 = x[a][0], d2 = y[a][0];
    for (int &k : x[a])
      k -= d1;
    for (int &k : y[a])
      k -= d2;
    if (i & 1) {
      for (int &k : x[a])
        k = -k;
      for (int &k : y[a])
        k = -k;
    } else {
      swap(x[a], y[a]);
      for (int &k : y[a])
        k = -k;
    }
    d1 = x[a][0];
    d2 = y[a][0];
    for (int &k : x[a])
      k -= d1;
    for (int &k : y[a])
      k -= d2;
    if (x[0] == x[a] && y[0] == y[a])
      return true;
  }
  return false;
}
int main() {
  int n;
  while (scanf("%d", &n), n) {
    rep(i, n + 1) {
      int m;
      scanf("%d", &m);
      x[i] = y[i] = vector<int>(m);
      rep(j, m) scanf("%d%d", &x[i][j], &y[i][j]);
    }
    for (int i = 1; i <= n; i++) {
      if (judge(i)) {
        printf("%d\\n", i);
        continue;
      }
      reverse(x[i].begin(), x[i].end());
      reverse(y[i].begin(), y[i].end());
      if (judge(i)) {
        printf("%d\\n", i);
      }
    }
    puts("+++++");
  }
}
Problem p00717 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_N 1355

int x[MAX_N][4], y[MAX_N][4];
int X[MAX_N][MAX_N], Y[MAX_N][MAX_N];
int n, m, M, cnt;

int main() {
  while (true) {
    if (cnt >= 1) {
      cout << "+++++" << endl;
    }
    cnt++;
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    memset(X, 0, sizeof(X));
    memset(Y, 0, sizeof(Y));
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
      cin >> x[i][0] >> y[i][0];
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < M; j++) {
        x[j][i + 1] = -y[j][i];
        y[j][i + 1] = x[j][i];
      }
    }
    for (int i = 1; i <= n; i++) {
      cin >> m;
      for (int j = 0; j < m; j++) {
        cin >> X[i][j] >> Y[i][j];
      }
      int same = 8;
      if (M != m) {
        same = 0;
      } else {
        for (int j = 0; j < 4; j++) {
          int X1 = x[0][j] - X[i][0], Y1 = y[0][j] - Y[i][0];
          for (int k = 1; k < M; k++) {
            if ((x[k][j] - X[i][k] != X1 || y[k][j] - Y[i][k] != Y1) &&
                same == 8 - j) {
              same--;
            }
          }
        }
        for (int j = 0; j < 4; j++) {
          int X1 = x[0][j] - X[i][M - 1], Y1 = y[0][j] - Y[i][M - 1];
          for (int k = 1; k < M; k++) {
            if ((x[k][j] - X[i][M - 1 - k] != X1 ||
                 y[k][j] - Y[i][M - 1 - k] != Y1) &&
                same == 4 - j) {
              same--;
            }
          }
        }
      }
      if (same >= 1) {
        cout << i << endl;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

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

#define MAX_N 1355

int x[MAX_N][4], y[MAX_N][4];
int X[MAX_N][MAX_N], Y[MAX_N][MAX_N];
int n, m, M, cnt;

int main() {
  while (true) {
    if (cnt >= 1) {
      cout << "+++++" << endl;
    }
    cnt++;
    memset(x, 0, sizeof(x));
    memset(y, 0, sizeof(y));
    memset(X, 0, sizeof(X));
    memset(Y, 0, sizeof(Y));
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> M;
    for (int i = 0; i < m; i++) {
      cin >> x[i][0] >> y[i][0];
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < M; j++) {
        x[j][i + 1] = -y[j][i];
        y[j][i + 1] = x[j][i];
      }
    }
    for (int i = 1; i <= n; i++) {
      cin >> m;
      for (int j = 0; j < m; j++) {
        cin >> X[i][j] >> Y[i][j];
      }
      bool same = true;
      if (M != m) {
        same = false;
      } else {
        for (int j = 0; j < 4; j++) {
          int X1 = x[0][j] - X[i][0], Y1 = y[0][j] - Y[i][0];
          for (int k = 1; k < M; k++) {
            if (x[k][j] - X[i][k] != X1 || y[k][j] - Y[i][k] != Y1) {
              same = false;
            }
          }
        }
      }
      if (same == true) {
        cout << i << endl;
      }
    }
  }
  return 0;
}
Problem p00718 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <iostream>
#include <string>

#pragma warning(disable : 4996)

using namespace std;

int n;
string S, T;

int main() {
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    cin >> S >> T;

    int s = 0, t = 0;

    int pos = 0;

    while (pos < S.size()) {
      int mult = 1;

      if (isdigit(S[pos])) {
        mult = S[pos] - 48;
        pos++;
      }

      switch (S[pos]) {
      case 'm':
        s += mult * 1000;
        break;
      case 'c':
        s += mult * 100;
        break;
      case 'x':
        s += mult * 10;
        break;
      case 'i':
        s += mult * 1;
        break;
      }

      pos++;
    }

    pos = 0;

    while (pos < T.size()) {
      int mult = 1;

      if (isdigit(T[pos])) {
        mult = T[pos] - 48;
        pos++;
      }

      switch (T[pos]) {
      case 'm':
        t += mult * 1000;
        break;
      case 'c':
        t += mult * 100;
        break;
      case 'x':
        t += mult * 10;
        break;
      case 'i':
        t += mult * 1;
        break;
      }

      pos++;
    }

    t += s;

    int r = 1000;

    while (r > 0) {
      if (t / r) {
        if ((t / r) != 1) {
          printf("%d", t / r);
        }

        switch (r) {
        case 1000:
          printf("m");
          break;
        case 100:
          printf("c");
          break;
        case 10:
          printf("x");
          break;
        case 1:
          printf("i");
          break;
        }
      }

      t = t % r;
      r /= 10;
    }

    printf("\\n");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <iostream>
#include <string>

using namespace std;

int n;
string S, T;

int main() {
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    cin >> S >> T;

    int s = 0, t = 0;

    int pos = 0;

    while (pos < S.size()) {
      int mult = 1;

      if (isdigit(pos)) {
        mult = S[pos] - 48;
        pos++;
      }

      switch (S[pos]) {
      case 'm':
        s += mult * 1000;
        break;
      case 'c':
        s += mult * 100;
        break;
      case 'x':
        s += mult * 10;
        break;
      case 'i':
        s += mult * 1;
        break;
      }
    }

    pos = 0;

    while (pos < T.size()) {
      int mult = 1;

      if (isdigit(pos)) {
        mult = T[pos] - 48;
        pos++;
      }

      switch (T[pos]) {
      case 'm':
        t += mult * 1000;
        break;
      case 'c':
        t += mult * 100;
        break;
      case 'x':
        t += mult * 10;
        break;
      case 'i':
        t += mult * 1;
        break;
      }
    }

    int r = 1000;

    while (r > 0) {
      if (t / r) {
        if (t / r != 1) {
          printf("%d", t / r);
        }

        switch (r) {
        case 1000:
          printf("m");
          break;
        case 100:
          printf("c");
          break;
        case 10:
          printf("x");
          break;
        case 1:
          printf("i");
          break;
        }
      }

      t = t % r;
      r /= 10;
    }
  }

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const string MCXI_STR("mcxi");
const VI MCXI_NUM({1000, 100, 10, 1});

int decode(string s) {
  int res = 0;

  for (int i = 0; i < (int)s.size(); i++) {
    if (isalpha(s[i])) {
      res += MCXI_NUM[MCXI_STR.find(s[i])];
    } else {
      res += MCXI_NUM[MCXI_STR.find(s[i + 1])] * (s[i] - '0');
      i++;
    }
  }

  return res;
}

string encode(int n) {
  string res;

  for (int i = 0; i < (int)MCXI_NUM.size(); i++) {
    int k = n / MCXI_NUM[i];

    if (k > 1) {
      res += k + '0';
    }
    if (k) {
      res += MCXI_STR[i];
    }

    n %= MCXI_NUM[i];
  }

  return res;
}

int main(void) {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string s1, s2;
    int n1, n2;

    cin >> s1 >> s2;

    n1 = decode(s1);
    n2 = decode(s2);

    cout << encode(n1 + n2) << endl;
  }

  return 0;
}

Error: 0
--- 11
--- 19
--- 3x
--- 1
--- 9
--- x
--- 122
--- 488
--- 6cx
--- 1201
--- 4798
--- 5m9c9x9i
--- 999
--- 1
--- m
--- 1
--- 9998
--- 9m9c9x9i
--- 1000
--- 1
--- mi
--- 1
--- 1000
--- mi
--- 1009
--- 1
--- mx
--- 9871
--- 128
--- 9m9c9x9i


Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const string MCXI_STR("mcxi");
const VI MCXI_NUM({1000, 100, 10, 1});

int decode(string s) {
  int res = 0;

  for (int i = 0; i < (int)s.size(); i++) {
    if (isalpha(s[i])) {
      res += MCXI_NUM[MCXI_STR.find(s[i])];
    } else {
      res += MCXI_NUM[MCXI_STR.find(s[i + 1])] * (s[i] - '0');
      i++;
    }
  }

  cerr << "--- " << res << endl;

  return res;
}

string encode(int n) {
  string res;

  for (int i = 0; i < (int)MCXI_NUM.size(); i++) {
    int k = n / MCXI_NUM[i];

    if (k > 1) {
      res += k + '0';
    }
    if (k) {
      res += MCXI_STR[i];
    }

    n %= MCXI_NUM[i];
  }

  cerr << "--- " << res << endl;

  return res;
}

int main(void) {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string s1, s2;
    int n1, n2;

    cin >> s1 >> s2;

    n1 = decode(s1);
    n2 = decode(s2);

    cout << encode(n1 + n2) << endl;
  }

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

#include <iostream>
using namespace std;
string s1, s2;

string g = "mcxi";
int mcxi(char c) {
  if (c == 'm')
    return 1000;
  else if (c == 'c')
    return 100;
  else if (c == 'x')
    return 10;
  else if (c == 'i')
    return 1;
}
int conv(string s) {
  int res = 0;
  int n = 1;
  for (string::iterator it = s.begin(); it != s.end(); it++) {
    char c = (*it);
    if (c > '0' && c <= '9')
      n = c - '0';
    else {
      res += n * mcxi(c);
      n = 1;
    }
  }
  return res;
}
string i2mcxi(int n) {
  int b = 1000;
  string res = "";
  for (int i = 0; i < 4; i++, b /= 10) {
    int t = n / b;
    if (t == 0)
      continue;
    else if (t > 1)
      res += t + '0';
    res += g[i];
    n = n % b;
  }
  return res;
}
void solve() { cout << i2mcxi(conv(s1) + conv(s2)) << endl; }
int main() {
  int n;
  cin >> n;
  for (; n > 0; n--) {
    cin >> s1 >> s2;

    solve();
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
string s1, s2;

char g[] = "mcxi";
int mcxi(char c) {
  if (c == 'm')
    return 1000;
  else if (c == 'c')
    return 100;
  else if (c == 'x')
    return 10;
  else if (c == 'i')
    return 1;
}
int conv(string s) {
  int res = 0;
  int n = 1;

  for (string::iterator it = s.begin(); it != s.end(); it++) {
    char c = *it;
    if (c > '0' && c <= '9')
      n = c - '0';
    else {
      res += n * mcxi(c);
      n = 1;
    }
  }
  return res;
}
string i2mcxi(int n) {
  int b = 1000;
  string res = "";
  for (int i = 0; i < 4; i++) {
    int t = n / t;
    if (t == 0)
      continue;
    else if (t > 1)
      res += t + '0';
    res += g[i];
  }
}
void solve() { cout << i2mcxi(conv(s1) + conv(s2)) << endl; }
int main() {
  int n;
  cin >> n;
  for (; n > 0; n--) {
    cin >> s1 >> s2;
    solve();
  }
  return 0;
}
Problem p00718 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

string mcxi(int x) {
  string s = "";
  int y;
  y = x % 10;
  if (y)
    s += 'i';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  y = x % 10;
  if (y)
    s += 'x';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  y = x % 10;
  if (y)
    s += 'c';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  y = x % 10;
  if (y)
    s += 'm';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  reverse(s.begin(), s.end());
  return s;
}

int main() {
  map<string, int> m;
  for (int x = 1; x <= 9999; x++)
    m[mcxi(x)] = x;
  int n;
  cin >> n;
  while (n--) {
    string s, t;
    cin >> s >> t;
    cout << mcxi(m[s] + m[t]) << endl;
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

string mcxi(int x) {
  string s = "";
  int y;
  y = x % 10;
  if (y)
    s += 'i';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  y = x % 10;
  if (y)
    s += 'x';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  y = x % 10;
  if (y)
    s += 'c';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  y = x % 10;
  if (y)
    s += 'm';
  if (y >= 2)
    s += y + '0';
  x /= 10;
  reverse(s.begin(), s.end());
  return s;
}

int hoge(string &s) {
  for (int x = 1;; x++)
    if (mcxi(x) == s)
      return x;
}

int main() {
  int n;
  cin >> n;
  while (n--) {
    string s, t;
    cin >> s >> t;
    cout << mcxi(hoge(s) + hoge(t)) << endl;
  }
}