Language: C++

#include <bits/stdc++.h>
using namespace std;
??
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)
??
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
??
int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
??
#define DOWN?? 0
#define RIGHT 1
#define UP?????? 2
#define LEFT?? 3
??
struct State {
????int x, y;
????int mem;
????int dir;
??
????State() :
????????????x(0),
????????????y(0),
????????????mem(0),
????????????dir(RIGHT) {}
??
????State(int x, int y, int mem, int dir) :
????????????x(x),
????????????y(y),
????????????mem(mem),
????????????dir(dir) {}
??
????bool operator<(const State & rhs) const {
????????if (x == rhs.x && y == rhs.y && mem == rhs.mem) return dir < rhs.dir;
????????if (x == rhs.x && y == rhs.y) return mem < rhs.mem;
????????if (x == rhs.x) return y < rhs.y;
????????return x < rhs.x;
????}
};
??
int main() {
????ios_base::sync_with_stdio(false); cin.tie(0);
????int R, C;
????cin >> R >> C;
????vector<string> prog(R);
????rep(i, R) cin >> prog[i];
??
????set<State> visited;
????queue<State> Q;
????ll ok = false;
??
????Q.push(State());
????while (!Q.empty()) {
????????State st = Q.front();
????????Q.pop();
??
????????st.x = (st.x + C) % C;
????????st.y = (st.y + R) % R;
??
????????if (visited.find(st) != visited.end())
????????????continue;
??????????
????????visited.insert(st);
??
????????char p;
????????p = prog[st.y][st.x];
??
????????if (p == '@') {
????????????ok = true;
????????????break;
????????}
??
????????switch (p) {
????????????case '0'...'9':
????????????????st.mem = p - '0';
????????????????break;
????????????case '_':
????????????????if (st.mem == 0) st.dir = RIGHT;
????????????????else st.dir = LEFT;
????????????????break;
????????????case '|':
????????????????if (st.mem == 0) st.dir = DOWN;
????????????????else st.dir = UP;
????????????????break;
????????????case '+':
????????????????st.mem = (st.mem + 1) % 16;
????????????????break;
????????????case '-':
????????????????st.mem = st.mem - 1;
????????????????if (st.mem < 0) st.mem += 16;
????????????????break;
????????????case '^':
????????????????st.dir = UP;
????????????????break;
????????????case 'v':
????????????????st.dir = DOWN;
????????????????break;
????????????case '<':
????????????????st.dir = LEFT;
????????????????break;
????????????case '>':
????????????????st.dir = RIGHT;
????????????????break;
????????}
??
????????if (p != '?') {
????????????Q.push(State(st.x + dx[st.dir], st.y + dy[st.dir], st.mem, st.dir));
????????} else {
????????????Q.push(State(st.x + dx[LEFT],???? st.y + dy[LEFT],?? st.mem, LEFT));
????????????Q.push(State(st.x + dx[RIGHT],?? st.y + dy[RIGHT], st.mem, RIGHT));
????????????Q.push(State(st.x + dx[UP],???????? st.y + dy[UP],?????? st.mem, UP));
????????????Q.push(State(st.x + dx[DOWN],???? st.y + dy[DOWN],?? st.mem, DOWN));
????????}
????}
??????
????if (ok) cout << "YES" << endl;
????else cout << "NO" << endl;
????return 0;
}

Compiler output:
a.cc:17:9: warning: ISO C++11 requires whitespace after the macro name
   17 | #define DOWN?? 0
      |         ^~~~
a.cc:19:9: warning: ISO C++11 requires whitespace after the macro name
   19 | #define UP?????? 2
      |         ^~
a.cc:20:9: warning: ISO C++11 requires whitespace after the macro name
   20 | #define LEFT?? 3
      |         ^~~~
a.cc:3:1: error: expected unqualified-id before '?' token
    3 | ??
      | ^
a.cc:12:14: error: 'll' was not declared in this scope; did you mean 'ull'?
   12 | typedef pair<ll, ll> pll;
      |              ^~
      |              ull
a.cc:12:18: error: 'll' was not declared in this scope; did you mean 'ull'?
   12 | typedef pair<ll, ll> pll;
      |                  ^~
      |                  ull
a.cc:12:20: error: template argument 1 is invalid
   12 | typedef pair<ll, ll> pll;
      |                    ^
a.cc:12:20: error: template argument 2 is invalid
a.cc:13:1: error: expected unqualified-id before '?' token
   13 | ??
      | ^
a.cc:16:1: error: expected unqualified-id before '?' token
   16 | ??
      | ^
a.cc:46:1: error: expected unqualified-id before '?' token
   46 | ??
      | ^