Language: C++

#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;

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

const int MAX_H = 21;
const int MAX_W = 21;
const int MAX_M = 11;

int H, W;
string M[20];
bool vis[MAX_M][4][MAX_H][MAX_W];

bool run( int x, int y, int dir, int mem ) {
  
  if(vis[mem][dir][y][x]) return 0;
  vis[mem][dir][y][x] = 1;
  
  bool flag = 0;
  
  switch(M[y][x]) {
  case '<': dir = 0; break;
  case '>': dir = 2; break;
  case '^': dir = 1; break;
  case 'v': dir = 3; break;
  case '_': dir = ( mem ? 0 : 2 ); break;
  case '|': dir = ( mem ? 1 : 3 ); break;
  case '?': flag = 1; break;
  case '.': break;
  case '@': return 1;
  case '+': mem = ( mem + 1 ) % 16; break;
  case '-': mem = ( mem + 15 ) % 16; break;
  default:
    if(isdigit(M[y][x])) {
      mem = M[y][x]-'0';
    }
  }

  if(flag) {
    for(int i=0; i<4; i++) {
      if(run((x+dx[i])%W, (y+dy[i])%H, i, mem)) return 1;
    }
    return 0;
  }
  
  return run((x+dx[dir])%W, (y+dy[dir])%H, dir, mem);
}

int main() {
  
  cin >> H >> W;
  cin.ignore();
  
  for(int i=0; i<H; i++) getline(cin, M[i]);
  
  if(run(0, 0, 2, 0)) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Compiler output:
a.cc:15:1: error: 'string' does not name a type
   15 | string M[20];
      | ^~~~~~
a.cc: In function 'bool run(int, int, int, int)':
a.cc:25:10: error: 'M' was not declared in this scope
   25 |   switch(M[y][x]) {
      |          ^
a.cc: In function 'int main()':
a.cc:55:3: error: 'cin' was not declared in this scope
   55 |   cin >> H >> W;
      |   ^~~
a.cc:5:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    4 | #include <cstring>
  +++ |+#include <iostream>
    5 | using namespace std;
a.cc:58:39: error: 'M' was not declared in this scope
   58 |   for(int i=0; i<H; i++) getline(cin, M[i]);
      |                                       ^
a.cc:58:26: error: 'getline' was not declared in this scope
   58 |   for(int i=0; i<H; i++) getline(cin, M[i]);
      |                          ^~~~~~~
a.cc:60:23: error: 'cout' was not declared in this scope
   60 |   if(run(0, 0, 2, 0)) cout << "YES" << endl;
      |                       ^~~~
a.cc:60:23: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:60:40: error: 'endl' was not declared in this scope
   60 |   if(run(0, 0, 2, 0)) cout << "YES" << endl;
      |                                        ^~~~
a.cc:5:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    4 | #include <cstring>
  +++ |+#include <ostream>
    5 | using namespace std;
a.cc:61:8: error: 'cout' was not declared in this scope
   61 |   else cout << "NO" << endl;
      |        ^~~~
a.cc:61:8: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:61:24: error: 'endl' was not declared in this scope
   61 |   else cout << "NO" << endl;
      |                        ^~~~
a.cc:61:24: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'