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

#include <cstdio>
#include <iostream>

using namespace std;

char field[8][8];

bool check(int y, int x) {
  return 0 <= y && y < 8 && 0 <= x && x < 8 && field[y][x];
}

int main(void) {
  int i, j, y, x;

  while (cin >> field[0]) {
    for (i = 1; i < 8; i++) {
      cin >> field[i];
    }

    for (i = 0; i < 8; i++) {
      for (j = 0; j < 8; j++) {
        field[i][j] -= '0';
      }
    }

    for (y = 0; y < 8; y++) {
      for (x = 0; x < 8; x++) {
        if (field[y][x] == 1) {
          if (check(y + 1, x) && check(y + 2, x))
            cout << "B" << endl;
          else if (check(y, x + 1) && check(y, x + 2))
            cout << "C" << endl;
          else if (check(y + 1, x) && check(y, x + 1) && check(y + 1, x + 1))
            cout << "A" << endl;
          else if (check(y + 1, x) && check(y + 1, x - 1) &&
                   check(y + 2, x - 1))
            cout << "D" << endl;
          else if (check(y, x + 1) && check(y + 1, x + 1) &&
                   check(y + 1, x + 2))
            cout << "E" << endl;
          else if (check(y + 1, x) && check(y + 1, x + 1) &&
                   check(y + 2, x + 1))
            cout << "F" << endl;
          else if (check(y, x + 1) && check(y + 1, x) && check(y + 1, x - 1))
            cout << "G" << endl;
          y = x = 8;
        }
      }
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int mass[8][8];

BEGIN:
  while (scanf("%d%d%d%d%d%d%d%d", (*mass[0]), (*mass[0]) + 1, (*mass[0]) + 2,
               (*mass[0]) + 3, (*mass[0]) + 4, (*mass[0]) + 5, (*mass[0]) + 6,
               (*mass[0]) + 7) != EOF) {
    for (int i = 1; i < 8; i++) {
      scanf("%d%d%d%d%d%d%d%d", (*mass[i]), (*mass[i]) + 1, (*mass[i]) + 2,
            (*mass[i]) + 3, (*mass[i]) + 4, (*mass[i]) + 5, (*mass[i]) + 6,
            (*mass[i]) + 7);
    }
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        if (mass[i][j]) {
          if (j == 7) {
            if (mass[i + 1][j]) {
              cout << (mass[i + 1][j - 1] ? "D\\n" : "B\\n");
            }
          } else if (j == 0) {
            if (mass[i][j + 1]) {
              if (mass[i + 1][j])
                cout << "A\\n";
              else if (mass[i][j + 2])
                cout << "C\\n";
              else
                cout << "E\\n";
            } else
              cout << (mass[i + 1][j + 1] ? "F\\n" : "B\\n");
          } else {
            if (mass[i][j + 2])
              cout << "C\\n";
            else if (mass[i][j + 1]) {
              if (mass[i + 1][j]) {
                cout << (mass[i + 1][j + 1] ? "A\\n" : "G\\n");
              } else
                cout << "E\\n";
            } else if (mass[i + 2][j])
              cout << "B\\n";
            else
              cout << (mass[i + 1][j + 1] ? "F\\n" : "D\\n");
          }
          goto BEGIN;
        }
      }
    }
  }
  return 0;
}
Problem p00036 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
string str[10];
void ans(int i, int k) {
  if (str[i][k + 1] == '1' && str[i + 1][k + 1] == '1' &&
      str[i + 1][k] == '1') {
    cout << "A" << endl;
  } else if (str[i + 1][k] == '1' && str[i + 2][k] == '1' &&
             str[i + 3][k] == '1') {
    cout << "B" << endl;
  } else if (str[i][k + 1] == '1' && str[i][k + 2] == '1' &&
             str[i][k + 3] == '1') {
    cout << "C" << endl;
  } else if (str[i + 1][k] == '1' && str[i + 1][k - 1] == '1' &&
             str[i + 2][k - 1] == '1') {
    cout << "D" << endl;
  } else if (str[i][k + 1] == '1' && str[i + 1][k + 1] == '1' &&
             str[i + 1][k + 2] == '1') {
    cout << "E" << endl;
  } else if (str[i + 1][k] == '1' && str[i + 1][k + 1] == '1' &&
             str[i + 2][k + 1] == '1') {
    cout << "F" << endl;
  } else {
    cout << "G" << endl;
  }
}

int main() {

  while (1) {
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++)
        str[i][j] = 0;
    }
    for (int i = 0; i < 8; i++)
      if (!(cin >> str[i]))
        return 0;

    for (int i = 0; i < 64; i++)
      if (str[i / 8][i % 8] == '1') {
        ans(i / 8, i % 8);
        break;
      }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
string str[8];
void ans(int i, int k) {
  if (str[i][k + 1] == '1' && str[i + 1][k + 1] == '1' &&
      str[i + 1][k] == '1') {
    cout << "A" << endl;
  } else if (str[i + 1][k] == '1' && str[i + 2][k] == '1' &&
             str[i + 3][k] == '1') {
    cout << "B" << endl;
  } else if (str[i][k + 1] == '1' && str[i][k + 2] == '1' &&
             str[i][k + 3] == '1') {
    cout << "C" << endl;
  } else if (str[i + 1][k] == '1' && str[i + 1][k - 1] == '1' &&
             str[i + 2][k - 1] == '1') {
    cout << "D" << endl;
  } else if (str[i][k + 1] == '1' && str[i + 1][k + 1] == '1' &&
             str[i + 1][k + 2] == '1') {
    cout << "E" << endl;
  } else if (str[i + 1][k] == '1' && str[i + 1][k + 1] == '1' &&
             str[i + 2][k + 1] == '1') {
    cout << "F" << endl;
  } else if (str[i][k + 1] == '1' && str[i + 1][k] == '1' &&
             str[i + 1][k - 1] == '1') {
    cout << "G" << endl;
  }
}

int main() {

  while (1) {

    for (int i = 0; i < 8; i++)
      if (!(cin >> str[i]))
        return 0;

    for (int i = 0; i < 64; i++)

      if (str[i / 8][i % 8] == '1')
        ans(i / 8, i % 8);
  }
}
Problem p00036 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char f[8][8];
  int x, y, i, j;
  while (1) {
    x = y = -1;
    for (i = 0; i < 8; i++)
      cin >> f[i];
    if (cin.eof())
      break;
    for (x = 0; x < 8; x++) {
      for (y = 0; y < 8; y++) {
        if (f[x][y] == '1') {
          i = x;
          j = y;
          break;
        }
      }
      if (i == x && j == y)
        break;
    }
    if (i < 7 && j < 7 && f[i + 1][j] == '1' && f[i][j + 1] == '1' &&
        f[i + 1][j + 1] == '1')
      printf("A\\n");
    else if (i < 5 && f[i + 3][j] == '1')
      printf("B\\n");
    else if (j < 5 && f[i][j + 3] == '1')
      printf("C\\n");
    else if (i < 6 && j > 0 && f[i + 2][j - 1] == '1')
      printf("D\\n");
    else if (i < 7 && j < 6 && f[i + 1][j + 2] == '1')
      printf("E\\n");
    else if (i < 6 && j < 7 && f[i + 2][j + 1] == '1')
      printf("F\\n");
    else if (i < 7 && j < 7 && j > 0 && f[i][j + 1] == '1' &&
             f[i + 1][j - 1] == '1')
      printf("G\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

char judge(vector<string> a) {
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      if (a.at(i)[j] == '1') {
        // not succession
        if (a[i].at(j + 1) != '1') {
          if (a[i + 1].at(j - 1) == '1') {
            return 'D';
          } else if (a[i + 1].at(j + 1) == '1') {
            return 'F';
          } else {
            return 'B';
          }
        } else {
          // in succession
          if (a[i].at(j + 2) == '1') {
            return 'C';
          } else if (a[i + 1].at(j + 2) == '1') {
            return 'E';
          } else if (a[i + 1].at(j - 1) == '1') {
            return 'G';
          } else {
            return 'A';
          }
        }
      }
    }
  }
  return 'N';
}

int main() {

  while (true) {
    vector<string> a;
    for (int j = 0; j < 8; j++) {
      string s;
      cin >> s;
      a.push_back(s);
    }

    if (!cin) {
      break;
    }

    cout << judge(a) << endl;
  }

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

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

int xb[7][3] = {{1, 0, 1}, {0, 0, 0}, {1, 2, 3}, {0, -1, -1},
                {1, 1, 2}, {0, 1, 1}, {1, 0, -1}};

int yb[7][3] = {{0, 1, 1}, {1, 2, 3}, {0, 0, 0}, {1, 1, 2},
                {0, 1, 1}, {1, 1, 2}, {0, 1, 1}};

int main() {
  string field[8];
  while (getline(cin, field[0])) {
    for (int i = 1; i < 8; i++)
      getline(cin, field[i]);

    char ans = '\\0';
    rep(y, 8) {
      rep(x, 8) {
        if (field[y][x] == '1') {
          // cerr << "x: " << x << " " << "y: " << y << endl;
          rep(i, 8) {
            bool f = true;
            rep(j, 3) {
              int nx = x + xb[i][j];
              int ny = y + yb[i][j];
#if 1
              if (!(0 <= nx && nx < 8 && 0 <= ny && ny < 8 &&
                    field[ny][nx] == '1')) {
                f = false;
                break;
              }
#endif
            }
            if (f) {
              ans = 'A' + i;
              goto END;
            }
          }
        }
      }
    }
  END:
    cout << ans << endl;
    getline(cin, field[0]);
  }
  return 0;
}

Error: 0

Fixed submission:

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

int xb[7][3] = {{1, 0, 1}, {0, 0, 0}, {1, 2, 3}, {0, -1, -1},
                {1, 1, 2}, {0, 1, 1}, {1, 0, -1}};

int yb[7][3] = {{0, 1, 1}, {1, 2, 3}, {0, 0, 0}, {1, 1, 2},
                {0, 1, 1}, {1, 1, 2}, {0, 1, 1}};

int main() {
  string field[8];
  while (getline(cin, field[0])) {
    for (int i = 1; i < 8; i++)
      getline(cin, field[i]);

    char ans = '\\0';
    rep(y, 8) {
      rep(x, 8) {
        if (field[y][x] == '1') {
          // cerr << "x: " << x << " " << "y: " << y << endl;
          rep(i, 8) {
            bool f = true;
            rep(j, 3) {
              int nx = xb[i][j];
              int ny = yb[i][j];
              if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
                if (field[y + ny][x + nx] != '1') {
                  f = false;
                  break;
                }
              }
            }
            if (f) {
              ans = 'A' + i;
              goto END;
            }
          }
        }
      }
    }
  END:
    cout << ans << endl;
    getline(cin, field[0]);
  }
  return 0;
}
Problem p00036 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define INF (1 << 29)
#define EPS (1e-10)
#define make_pair mp
#define pb push_bacck

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

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int bx[7][4] = {{0, 1, 0, 1}, {0, 0, 0, 0}, {0, 1, 2, 3}, {1, 0, 1, 0},
                {0, 1, 1, 2}, {0, 0, 1, 1}, {1, 2, 0, 1}};
int by[7][4] = {{0, 0, 1, 1}, {0, 1, 2, 3}, {0, 0, 0, 0}, {0, 1, 1, 2},
                {0, 0, 1, 1}, {0, 1, 1, 2}, {0, 0, 1, 1}};

int main() {
  string board[8];
  string line;
  int l = 0;
  while (cin >> line) {
    board[l] = line;
    if (++l == 8) {
      for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
          for (int k = 0; k < sizeof(bx); k++) {
            bool ok = true;
            for (int l = 0; l < 4; l++) {
              int x = j + bx[k][l], y = i + by[k][l];
              if (x < 0 || 8 <= x || y < 0 || 8 <= y || board[y][x] != '1') {
                ok = false;
                break;
              }
            }
            if (ok) {
              cout << char('A' + k) << endl;
              goto end;
            }
          }
        }
      }
    end:;
      l = 0;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define INF (1 << 29)
#define EPS (1e-10)
#define make_pair mp
#define pb push_bacck

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

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int bx[7][4] = {{0, 1, 0, 1}, {0, 0, 0, 0}, {0, 1, 2, 3}, {1, 0, 1, 0},
                {0, 1, 1, 2}, {0, 0, 1, 1}, {1, 2, 0, 1}};
int by[7][4] = {{0, 0, 1, 1}, {0, 1, 2, 3}, {0, 0, 0, 0}, {0, 1, 1, 2},
                {0, 0, 1, 1}, {0, 1, 1, 2}, {0, 0, 1, 1}};

int main() {
  string board[8];
  while (1) {
    for (int i = 0; i < 8; i++) {
      cin >> board[i];
    }
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        for (int k = 0; k < sizeof(bx); k++) {
          bool ok = true;
          for (int l = 0; l < 4; l++) {
            int x = j + bx[k][l], y = i + by[k][l];
            if (x < 0 || 8 <= x || y < 0 || 8 <= y || board[y][x] != '1') {
              ok = false;
              break;
            }
          }
          if (ok) {
            cout << char('A' + k) << endl;
            goto end;
          }
        }
      }
    }
  end:;
  }
}
Problem p00036 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <array>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define _X_ 0
#define _Y_ 1
int main() {
  while (true) {
    std::vector<std::array<int, 2>> p;
    p.reserve(4);
    for (int i = 0; i < 8; i++) {
      std::string temp;
      std::cin >> temp;
      std::stringstream st(temp);
      for (int j = 0; j < 8; j++) {
        char foo;
        st >> foo;
        if (foo == '1') {
          p.push_back({j, i});
        }
      }
    }
    if (std::cin.eof()) {
      break;
    }
    if (p[0][_Y_] == p[1][_Y_]) {
      if (p[0][_X_] == p[2][_X_]) {
        std::cout << 'A' << std::endl;
      } else if (p[0][_Y_] == p[2][_Y_]) {
        std::cout << 'C' << std::endl;
      } else if (p[1][_X_] == p[2][_X_]) {
        std::cout << 'E' << std::endl;
      } else if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'G' << std::endl;
      }
    } else {
      if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'B' << std::endl;
      } else if (p[0][_X_] > p[3][_X_]) {
        std::cout << 'D' << std::endl;
      } else {
        std::cout << 'F' << std::endl;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <array>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#define _X_ 0
#define _Y_ 1
int main() {
  while (true) {
    std::vector<std::array<int, 2>> p;
    p.reserve(4);
    for (int i = 0; i < 8; i++) {
      std::string temp;
      std::cin >> temp;
      std::stringstream st(temp);
      for (int j = 0; j < 8; j++) {
        char foo;
        st >> foo;
        if (foo == '1') {
          p.push_back({j, i});
        }
      }
    }
    if (p[0][_Y_] == p[1][_Y_]) {
      if (p[0][_X_] == p[2][_X_]) {
        std::cout << 'A' << std::endl;
      } else if (p[0][_Y_] == p[2][_Y_]) {
        std::cout << 'C' << std::endl;
      } else if (p[1][_X_] == p[2][_X_]) {
        std::cout << 'E' << std::endl;
      } else if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'G' << std::endl;
      }
    } else {
      if (p[0][_X_] == p[3][_X_]) {
        std::cout << 'B' << std::endl;
      } else if (p[0][_X_] > p[3][_X_]) {
        std::cout << 'D' << std::endl;
      } else {
        std::cout << 'F' << std::endl;
      }
    }
  }
  return 0;
}
Problem p00036 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char str[20][20];
  while (1) {
    for (int i = 4; i < 12; i++) {
      for (int j = 4; j < 12; j++) {
        cin >> str[i][j];
        if (cin.eof())
          return 0;
      }
    }
    char ans;
    for (int i = 4; i < 12; i++) {
      for (int j = 4; j < 12; j++) {
        if (str[i][j] == '1' && str[i][j + 1] == '1' && str[i + 1][j] == '1' &&
            str[i + 1][j + 1] == '1')
          ans = 'A';
        else if (str[i][j] == '1' && str[i + 1][j] == '1' &&
                 str[i + 2][j] == '1' && str[i + 3][j] == '1')
          ans = 'B';
        else if (str[i][j] == '1' && str[i][j + 1] == '1' &&
                 str[i][j + 2] == '1' && str[i][j + 3] == '1')
          ans = 'C';
        else if (str[i][j] == '1' && str[i + 1][j - 1] == '1' &&
                 str[i + 1][j] == '1' && str[i + 2][j - 1] == '1')
          ans = 'D';
        else if (str[i][j] == '1' && str[i][j + 1] == '1' &&
                 str[i + 1][j + 1] == '1' && str[i + 1][j + 2] == '1')
          ans = 'E';
        else if (str[i][j] == '1' && str[i + 1][j] == '1' &&
                 str[i + 1][j + 1] == '1' && str[i + 2][j + 1] == '1')
          ans = 'F';
        else if (str[i][j] == '1' && str[i][j + 1] == '1' &&
                 str[i + 1][j - 1] == '1' && str[i + 1][j] == '1')
          ans = 'G';
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string str[8];
  while (1) {
    for (int i = 0; i < 8; i++)
      cin >> str[i];
    if (cin.eof())
      return 0;
    char ans;
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        if (str[i][j] == '1' && str[i][j + 1] == '1' && str[i + 1][j] == '1' &&
            str[i + 1][j + 1] == '1')
          ans = 'A';
        else if (str[i][j] == '1' && str[i + 1][j] == '1' &&
                 str[i + 2][j] == '1' && str[i + 3][j] == '1')
          ans = 'B';
        else if (str[i][j] == '1' && str[i][j + 1] == '1' &&
                 str[i][j + 2] == '1' && str[i][j + 3] == '1')
          ans = 'C';
        else if (str[i][j] == '1' && str[i + 1][j - 1] == '1' &&
                 str[i + 1][j] == '1' && str[i + 2][j - 1] == '1')
          ans = 'D';
        else if (str[i][j] == '1' && str[i][j + 1] == '1' &&
                 str[i + 1][j + 1] == '1' && str[i + 1][j + 2] == '1')
          ans = 'E';
        else if (str[i][j] == '1' && str[i + 1][j] == '1' &&
                 str[i + 1][j + 1] == '1' && str[i + 2][j + 1] == '1')
          ans = 'F';
        else if (str[i][j] == '1' && str[i][j + 1] == '1' &&
                 str[i + 1][j - 1] == '1' && str[i + 1][j] == '1')
          ans = 'G';
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00036 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  char c[10][10];
  while (cin >> c[0][0]) {
    for (int i = 0; i < 8; i++)
      for (int j = 0; j < 8; j++) {
        if (i == 0 && j == 0)
          continue;
        cin >> c[i][j];
      }
    int a, b;
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        if (c[i][j] == '1') {
          a = i;
          b = j;
          goto C;
        }
      }
    }
  C:
    if (c[a][b + 1] == '1') {
      if (c[a + 1][b] == '1') {
        if (c[a + 1][b + 1] == '1')
          cout << 'A';
        else
          cout << 'G';
      } else {
        if (c[a + 1][b + 1] == '1')
          cout << 'E';
        else
          cout << 'C';
      }
    } else if (c[a + 1][b + 1] == '1')
      cout << 'F';
    else if (c[a + 1][b - 1] == '1')
      cout << 'D';
    else
      cout << 'B';
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

struct ca {
  int x;
  int y;
};

int main() {
  ca l[4];
  char c;
  while (true) {
    int a = 0;
    for (int i = 0; i < 8; i++) {
      for (int j = 1; j < 8; j++) {
        cin >> c;
        if (c == '1') {
          l[a].x = i;
          l[a].y = j;
          a++;
        }
      }
    }
    int x = l[0].x;
    int y = l[0].y;
    if (l[1].x == x && l[1].y == y + 1) {
      //[l0][l1]
      // ACEG
      if (l[3].x == x + 1 && l[3].y == y + 1)
        cout << 'A';
      else if (l[3].y == y + 3)
        cout << 'C';
      else if (l[3].x == x + 1 && l[3].y == y + 2)
        cout << 'E';
      else
        cout << 'G';
    } else if (l[1].x == x + 1 && l[1].y == y) {
      /*[l0]
        [l1]*/
      // BF
      if (l[3].x == x + 3 && l[3].y == y)
        cout << 'B';
      else
        cout << 'F';
    } else
      cout << 'D';
    cout << endl;
  }
  return 0;
}
Problem p00037 (C++) — buggy submission, verdict: Time Limit Exceeded

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

class Dot {
public:
  bool d[4];
  Dot() { d[0] = d[1] = d[2] = d[3] = false; }
};

int main() {
  Dot data[5][5];
  for (int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i / 2;
    if (i % 2 == 0) {
      for (int j = 0; j < 4; j++) {
        if (str[j] == '1') {
          data[y][j].d[0] = data[y][j + 1].d[2] = true;
        }
      }
    } else {
      for (int j = 0; j < 5; j++) {
        if (str[j] == '1') {
          data[y][j].d[1] = data[y + 1][j].d[3] = true;
        }
      }
    }
  }

  int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while (1) {
    for (int i = 0; i < 4; i++) {
      int t = (dir + i + 3) % 4;
      if (data[y][x].d[t]) {
        dir = t;
        x += d[t][0];
        y += d[t][1];
        switch (t) {
        case 0:
          cout << 'R';
          break;
        case 1:
          cout << 'D';
          break;
        case 2:
          cout << 'L';
          break;
        case 3:
          cout << 'U';
          break;
        }
        break;
      }
    }
    if (x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

class Dot {
public:
  bool d[4];
  Dot() { d[0] = d[1] = d[2] = d[3] = false; }
};

int main() {
  Dot data[5][5];
  for (int i = 0; i < 9; i++) {
    string str;
    getline(cin, str);
    int y = i / 2;
    if (i % 2 == 0) {
      for (int j = 0; j < 4; j++) {
        if (str[j] == '1') {
          data[y][j].d[0] = data[y][j + 1].d[2] = true;
        }
      }
    } else {
      for (int j = 0; j < 5; j++) {
        if (str[j] == '1') {
          data[y][j].d[1] = data[y + 1][j].d[3] = true;
        }
      }
    }
  }

  int d[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int x = 0;
  int y = 0;
  int dir = 0;
  while (1) {
    for (int i = 0; i < 3; i++) {
      int t = (dir + i + 3) % 4;
      if (data[y][x].d[t]) {
        dir = t;
        x += d[t][0];
        y += d[t][1];
        switch (t) {
        case 0:
          cout << 'R';
          break;
        case 1:
          cout << 'D';
          break;
        case 2:
          cout << 'L';
          break;
        case 3:
          cout << 'U';
          break;
        }
        break;
      }
    }
    if (x == 0 && y == 0) {
      cout << endl;
      break;
    }
  }
  return 0;
}