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

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

int main() {

  int w, h;
  while (cin >> h >> w, w + h) {
    char room[101][101];
    int t = 0;
    int now_x = 0, now_y = 0;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> room[i][j];
      }
    }

    while (1) {
      if (room[now_y][now_x] == '.')
        break;
      char c = room[now_y][now_x];
      if (c == '>')
        now_x++;
      if (c == '<')
        now_x--;
      if (c == 'v')
        now_y++;
      if (c == '^')
        now_y--;
      t++;
      if (t > w * h)
        break;
    }

    if (t > w * h)
      cout << "LOOP" << endl;
    else
      cout << now_x << " " << now_y << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {

  int w, h;
  while (cin >> h >> w, w + h) {
    char room[10][10];
    int t = 0;
    int now_x = 0, now_y = 0;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> room[i][j];
      }
    }

    while (1) {
      if (room[now_y][now_x] == '.')
        break;
      char c = room[now_y][now_x];
      if (c == '>')
        now_x++;
      if (c == '<')
        now_x--;
      if (c == 'v')
        now_y++;
      if (c == '^')
        now_y--;
      t++;
      if (t > w * h)
        break;
    }

    if (t > w * h)
      cout << "LOOP" << endl;
    else
      cout << now_x << " " << now_y << endl;
  }
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define SZ(n) (int)n.size()
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back

char ta[130][130];
int h, w, ny = 0, nx = 0, cnt = 0;
bool ok(int y, int x, int ny, int nx) {
  if (ny + y >= 0 && ny + y <= h - 1 && nx + x >= 0 && nx + x <= w - 1)
    return 1;
  else
    return 0;
}
int main() {

  while (cin >> h >> w, h + w) {
    cnt = 0;
    ny = nx = 0;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> ta[i][j];
    while (true) {
      // cout<<ny<<" "<<nx<<endl;
      if (ta[ny][nx] == '.') {
        cout << nx << " " << ny << endl;
        break;
      }
      if (cnt >= 50000) {
        cout << "LOOP" << endl;
        ;
        break;
      }
      if (ta[ny][nx] == '>')
        nx++;
      else if (ta[ny][nx] == '<')
        nx--;
      else if (ta[ny][nx] == '^')
        ny--;
      else if (ta[ny][nx] == 'v')
        ny++;
      cnt++;
    }
    for (int i = 0; i < 130; i++)
      for (int j = 0; j < 130; j++)
        ta[i][j] = ' ';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define SZ(n) (int)n.size()
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back

char ta[30][30];
int h, w, ny = 0, nx = 0, cnt = 0;
bool ok(int y, int x, int ny, int nx) {
  if (ny + y >= 0 && ny + y <= h - 1 && nx + x >= 0 && nx + x <= w - 1)
    return 1;
  else
    return 0;
}
int main() {

  while (cin >> h >> w, h + w) {
    cnt = 0;
    ny = nx = 0;
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> ta[i][j];
    while (true) {
      // cout<<ny<<" "<<nx<<endl;
      if (ta[ny][nx] == '.') {
        cout << nx << " " << ny << endl;
        break;
      }
      if (cnt >= 10000) {
        cout << "LOOP" << endl;
        ;
        break;
      }
      if (ta[ny][nx] == '>')
        nx++;
      else if (ta[ny][nx] == '<')
        nx--;
      else if (ta[ny][nx] == '^')
        ny--;
      else if (ta[ny][nx] == 'v')
        ny++;
      cnt++;
    }
    for (int i = 0; i < 30; i++)
      for (int j = 0; j < 30; j++)
        ta[i][j] = ' ';
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

int main() {
  int x, y, mapx, mapy, tmp0, tmp1, flag;
  char map[101][101], pmap;
  scanf("%d%d", &mapx, &mapy);
  while (mapx + mapy) {
    for (tmp0 = 0; tmp0 < mapx; tmp0++)
      scanf("%s", map[tmp0]);
    x = 0, y = 0, flag = 1;
    while (flag && flag != 100) {
      pmap = map[x][y];
      map[x][y] = 1;
      if (pmap == '>')
        y++;
      else if (pmap == '<')
        y--;
      else if (pmap == '^')
        x--;
      else if (pmap == 'v')
        x++;
      else if (pmap == '.')
        flag = 0;
      else
        flag = 100;
    }
    if (flag)
      puts("LOOP");
    else
      printf("%d %d\\n", y, x);
    scanf("%d%d", &mapx, &mapy);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define debug(A) puts(A)
#define debugp(A, B) printf(A, B)
#define debugs(A, B) scanf(A, B)
using namespace std;

int main() {
  int mapx, mapy;
  int x, y, tmp0 = 0, tmp1 = 0;
  char map[150][150] = {0}, tmpc = 1;
  scanf("%d %d", &mapx, &mapy);
  while (mapx + mapy) {
    scanf("%c", &tmpc);
    while (tmp0 < mapx) {
      tmp1 = 0;
      while (tmp1 < mapy) {
        scanf("%c", &map[tmp0][tmp1]);
        tmp1++;
      }
      scanf("%c", &tmpc);
      tmp0++;
    }
    tmp0 = 0, tmp1 = 0, tmpc = 1;
    x = 0, y = 0;
    while (tmpc) {
      if (map[x][y] == '>')
        y++;
      else if (map[x][y] == '<')
        y--;
      else if (map[x][y] == '^')
        x--;
      else if (map[x][y] == 'v')
        x++;
      else if (map[x][y] == '.')
        tmpc = 0;
      else
        tmpc = 0;
      // debugp("Debug: %c %d %d\\n", map[x][y], (x+1), (y+1));
    }
    printf("%d %d\\n", (x + 1), (y + 1));
    scanf("%d %d", &mapx, &mapy);
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

using namespace std;

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

string fie[200] = {};

int main() {
  int h, w;
  while (cin >> h >> w) {
    if (w == 0 && h == 0)
      break;

    rep(i, h) { cin >> fie[i]; }

    int y = 0, x = 0;

    int c = 0;
    while (c < 1000000) {
      c++;
      char ch = fie[y][x];
      if (ch == '>') {
        x++;
      } else if (ch == '<') {
        x--;
      } else if (ch == '^') {
        y--;
      } else if (ch == 'v') {
        y++;
      } else
        break;
    }
    if (c == 1000000)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

string fie[30] = {};

int main() {
  int h, w;
  while (cin >> h >> w) {
    if (w == 0 && h == 0)
      break;

    rep(i, h) { cin >> fie[i]; }

    int y = 0, x = 0;

    int c = 0;
    while (c < 1000000) {
      c++;
      char ch = fie[y][x];
      if (ch == '>') {
        x++;
      } else if (ch == '<') {
        x--;
      } else if (ch == '^') {
        y--;
      } else if (ch == 'v') {
        y++;
      } else
        break;
    }
    if (c == 1000000)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int H, W, x, y;
  while (cin >> H >> W) {
    if (H == 0 && W == 0)
      break;
    char space[W][H], c;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> space[j][i];
      }
    }
    x = y = 0;
    while (1) {
      c = space[x][y];
      space[x][y] = '0';
      if (c == '>')
        x++;
      else if (c == '<')
        x--;
      else if (c == 'v')
        y++;
      else if (c == '^')
        y--;
      else if (c == '.') {
        cout << x << ' ' << y << endl;
        break;
      } else if (c == '0') {
        cout << "LOOP" << endl;
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int H, W, x, y;
  while (cin >> H >> W) {
    if (H == 0 && W == 0)
      break;
    char space[H][W], c;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> space[j][i];
      }
    }
    x = y = 0;
    while (1) {
      c = space[x][y];
      space[x][y] = '0';
      if (c == '>')
        x++;
      else if (c == '<')
        x--;
      else if (c == 'v')
        y++;
      else if (c == '^')
        y--;
      else if (c == '.') {
        cout << x << ' ' << y << endl;
        break;
      } else if (c == '0') {
        cout << "LOOP" << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 1; i <= n; i++)
int main() {
  int h, w;
  while (cin >> h >> w, h, w) {
    char map[114][514];
    bool b[114][514] = {};
    rep(i, h) rep(j, w) cin >> map[i][j];
    int x = 1, y = 1;
    rep(i, 10010) {
      if (b[x][y]) {
        cout << "LOOP\\n";
        goto end;
      }
      b[x][y] = true;
      if (map[x][y] == '>')
        y++;
      else if (map[x][y] == '<')
        y--;
      else if (map[x][y] == '^')
        x--;
      else if (map[x][y] == 'v')
        x++;
      else {
        cout << --y << ' ' << --x << endl;
        goto end;
      }
    }
  end:;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int h, w;
  while (cin >> h >> w) {
    char map[114][514];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> map[i][j];
    int i = 0, j = 0;
    for (int p = 1; p < 100000; p++) {
      if (map[i][j] == '.') {
        cout << j << ' ' << i << endl;
        continue;
      } else if (map[i][j] == '>')
        j++;
      else if (map[i][j] == '<')
        j--;
      else if (map[i][j] == '^')
        i--;
      else if (map[i][j] == 'v')
        i++;
    }
    cout << "LOOP\\n";
  }
}
Problem p00104 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int w, h;
  while (cin >> h >> w, h) {
    string f[h];
    for (int i = 0; i < h; ++i) {
      cin >> f[i];
    }

    bool used[h][w];
    memset(used, 0, sizeof(used));

    int x = 0, y = 0;
    while (1) {
      if (used[y][x]) {
        cout << "LOOP" << endl;
        break;
      }
      if (f[y][x] == '.') {
        cout << x << " " << y << endl;
        break;
      }
      used[y][x] = true;

      if (f[y][x] == '>')
        x += 1;
      if (f[y][x] == '<')
        x -= 1;
      if (f[y][x] == '^')
        y -= 1;
      if (f[y][x] == 'v')
        y += 1;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int w, h;
  bool flag = false;
  char map[100 + 5][100 + 5];
  while (cin >> w >> h && (w || h)) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> map[i][j];
      }
    }
    int step = 0;
    int x = 0;
    int y = 0;
    while (1) {
      while (map[x][y] == '>') {
        x++;
        step++;
        // cout<<">"<<" ";
      }
      while (map[x][y] == '<') {
        x--;
        step++;
        // cout<<"<"<<" ";
      }
      while (map[x][y] == 'v') {
        y++;
        step++;
        // cout<<"v"<<" ";
      }
      while (map[x][y] == '^') {
        y--;
        step++;
        // cout<<"^"<<" ";
      }
      if (step > (w * h)) {
        flag = true;
        break;
      }
      if (map[x][y] == '.') {
        break;
      }
      if (flag)
        break;
    }
    if (flag)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
  // while(1);
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

/*
        0104:Magical Tiles
*/
#include <iostream>

using namespace std;

// GV
char map[101][101];

// FN
void refmaps(void);
void start(void);

int main(void) {
  while (1) {
    int W, H;

    refmaps();

    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        char c;
        cin >> c;
        map[i][j] = c;
      }
    }

    start();
  }
  return 0;
}

void refmaps(void) {
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      map[i][j] = '.';
    }
  }
}

void start(void) {
  int h = 0, w = 0;
  const int vx[4] = {1, 0, -1, 0}, vy[4] = {0, 1, 0, -1};
  const char vc[4] = {'>', 'v', '<', '^'};

  while (1) {
    if (map[h][w] == '.') {
      cout << w << ' ' << h << endl;
      return;
    } else if (map[h][w] == 'L') {
      cout << "LOOP" << endl;
      return;
    } else {
      for (int i = 0; i < 4; i++) {
        if (map[h][w] == vc[i]) {
          map[h][w] = 'L';
          h += vy[i];
          w += vx[i];
        }
      }
    }
  }
}

Error: TLE

Fixed submission:

/*
        0104:Magical Tiles
*/
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int H, W;
  while (1) {
    cin >> W >> H;
    if (H == 0 && W == 0) {
      break;
    }
    vector<vector<char>> tiles;
    vector<vector<int>> status;

    tiles.resize(W + 1);
    status.resize(W + 1);
    for (int i = 0; i < (int)tiles.size(); i++) {
      tiles[i].resize(H + 1);
      status[i].resize(H + 1);
    }

    for (int i = 0; i < (int)tiles.size() - 1; i++) {
      for (int j = 0; j < (int)tiles[i].size(); j++) {
        scanf("%c", &tiles[i][j]);
      }
    }

    for (int i = 0; i < (int)status.size(); i++) {
      for (int j = 0; j < (int)status[i].size(); i++) {
        status[i][j] = 0;
      }
    }

    int a = 0, b = 0;
    while (1) {
      if (tiles[a][b] == '.') {
        cout << b << ' ' << a << endl;
        break;
      } else if (status[a][b] == 1) {
        cout << "LOOP" << endl;
        break;
      } else {
        status[a][b] = 1;

        if (tiles[a][b] == '<') {
          // cout << "MOVE:" << '<' << endl;
          b--;
        } else if (tiles[a][b] == '>') {
          // cout << "MOVE:" << '>' << endl;
          b++;
        } else if (tiles[a][b] == '^') {
          // cout << "MOVE:" << '^' << endl;
          a--;
        } else if (tiles[a][b] == 'v') {
          // cout << "MOVE:" << 'v' << endl;
          a++;
        }
      }
    }
  }

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

#include <iostream>

using namespace std;
int H, W;
int x = 0, y = 0;
int rog[100][100];
bool check() {
  if (rog[x][y] == 0) {
    cout << "LOOP" << endl;
    return true;
  }

  return false;
}

int main() {
  char ma[100][100];

  while (cin >> H >> W, W + H) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> ma[j][i];
        rog[j][i] = 1;
      }
    }

    x = 0, y = 0;
    while (1) {
      if (ma[x][y] == '>') {
        x++;
        if (check())
          break;
      } else if (ma[x][y] == 'v') {
        y++;
        if (check())
          break;
      } else if (ma[x][y] == '<') {
        x--;
        if (check())
          break;
      } else if (ma[x][y] == '^') {
        y--;
        if (check())
          break;
      } else {
        cout << x << " " << y << endl;
        break;
      }

      rog[x][y] = 0;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int H, W;
int x = 0, y = 0;
int rog[100][100];
bool check() {
  if (rog[x][y] == 0) {
    cout << "LOOP" << endl;
    return true;
  }

  return false;
}

int main() {
  char ma[100][100];

  while (cin >> H >> W, W + H) {

    int x = 0, y = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> ma[j][i];
        rog[j][i] = 1;
      }
    }
    while (1) {
      if (ma[x][y] == '>') {
        x++;
        if (check())
          break;
      } else if (ma[x][y] == 'v') {
        y++;
        if (check())
          break;
      } else if (ma[x][y] == '<') {
        x--;
        if (check())
          break;
      } else if (ma[x][y] == '^') {
        y--;
        if (check())
          break;
      } else {
        cout << x << " " << y << endl;
        break;
      }

      rog[x][y] = 0;
    }
  }
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

char map[100][100];

int main() {
  int h, w;

  while (cin >> h >> w, h != 0 || w != 0) {
    int x, y;
    bool loop = false;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> map[j][i];
      }
    }
    x = 0;
    y = 0;
    for (int i = 1; i <= 10000; i++) {
      if (map[x][y] == '!') {
        loop = true;
        break;
      }
      if (map[x][y] == '.') {
        break;
      }
      if (map[x][y] == '>') {
        map[x][y] = '!';
        x++;
      } else if (map[x][y] == '<') {
        map[x][y] = '!';
        x--;
      } else if (map[x][y] == 'v') {
        map[x][y] = '!';
        y++;
      } else if (map[x][y] == '^') {
        map[x][y] = '!';
        y--;
      }
    }
    if (loop)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int h, w;

  while (cin >> h >> w, h != 0 || w != 0) {
    char map[h][w];
    int x, y;
    bool loop = false;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> map[j][i];
      }
    }
    x = 0;
    y = 0;
    for (int i = 1; i <= 10000; i++) {
      if (map[x][y] == '!') {
        loop = true;
        break;
      }
      if (map[x][y] == '.') {
        break;
      }
      if (map[x][y] == '>') {
        map[x][y] = '!';
        x++;
      } else if (map[x][y] == '<') {
        map[x][y] = '!';
        x--;
      } else if (map[x][y] == 'v') {
        map[x][y] = '!';
        y++;
      } else if (map[x][y] == '^') {
        map[x][y] = '!';
        y--;
      }
    }
    if (loop)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

#define MAX 100

int main(void) {
  int H, W;
  char tile[MAX][MAX];

  while (1) {

    int x = 0, y = 0;

    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        tile[i][j] = '.';
      }
    }

    cin >> H >> W;
    if (H == 0 && W == 0)
      break;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> tile[i][j];
      }
    }

    int cal = 0, sum = 0;
    cal = H * W;

    // for(int i = 0 ; i < H ; i++) {
    // for(int j = 0 ; j < W ; j++) {
    while (tile[x][y] != '.') {
      if (tile[x][y] == '>')
        y++, sum++;
      else if (tile[x][y] == '<')
        y--, sum++;
      else if (tile[x][y] == '^')
        x--, sum++;
      else if (tile[x][y] == 'v')
        x++, sum++;
      if (sum > cal)
        break;
      // cout << "x = " << x << endl << "y = " << y << endl;
    }
    if (sum <= cal)
      cout << y << ' ' << x << endl;
    else
      cout << "LOOP" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#define MAX 10

int main(void) {
  int H, W;
  char tile[MAX][MAX];

  while (1) {

    int x = 0, y = 0;

    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        tile[i][j] = '.';
      }
    }

    cin >> H >> W;
    if (H == 0 && W == 0)
      break;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> tile[i][j];
      }
    }

    int cal = 0, sum = 0;
    cal = H * W;

    // for(int i = 0 ; i < H ; i++) {
    // for(int j = 0 ; j < W ; j++) {
    while (tile[x][y] != '.') {
      if (tile[x][y] == '>')
        y++, sum++;
      else if (tile[x][y] == '<')
        y--, sum++;
      else if (tile[x][y] == '^')
        x--, sum++;
      else if (tile[x][y] == 'v')
        x++, sum++;
      if (sum > cal)
        break;
      // cout << "x = " << x << endl << "y = " << y << endl;
    }
    if (sum <= cal)
      cout << y << ' ' << x << endl;
    else
      cout << "LOOP" << endl;
  }
  return 0;
}
Problem p00104 (C++) — buggy submission, verdict: Runtime Error

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

int m, n, w, h;
char b[102][102];
bool v[102][102];

void dfs(int y, int x) {
  if (v[y][x]) {
    cout << "LOOP" << endl;
    return;
  }
  v[y][x] = 1;
  if (b[y][x] == '>') {
    dfs(y, x + 1);
    return;
  }
  if (b[y][x] == 'v') {
    dfs(y + 1, x);
    return;
  }
  if (b[y][x] == '<') {
    dfs(y, x - 1);
    return;
  }
  if (b[y][x] == '^') {
    dfs(y - 1, x);
    return;
  }
  cout << x << " " << y << endl;
}

int main() {
  while (cin >> h >> w, w || h) {
    for (int i = 0; i < h; i++)
      cin >> b[i];
    memset(v, 0, sizeof(v));
    dfs(0, 0);
  }
}

Error: TLE

Fixed submission:

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

int m, n, w, h;
char b[102][102];
bool v[102][102];

void dfs(int y, int x) {
  if (v[y][x])
    cout << "LOOP" << endl;
  v[y][x] = 1;
  if (b[y][x] == '>')
    dfs(y, x + 1);
  if (b[y][x] == 'v')
    dfs(y + 1, x);
  if (b[y][x] == '<')
    dfs(y, x - 1);
  if (b[y][x] == '^')
    dfs(y - 1, x);
  cout << x << " " << y << endl;
}

int main() {
  while (cin >> h >> w, w || h) {
    for (int i = 0; i < h; i++)
      cin >> b[i];
    memset(v, 0, sizeof(v));
    dfs(0, 0);
  }
}