Language: C++

#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for (int i = (a); i < (b); i++)
#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define sz(v) int(v.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

int n, x0, y0, t;
bool rd[55][55][4];

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

vector<tuple<int,int,int,int> > v;
bool seen[55][55][11][4][2];

int main() {
    scanf("%d %d %d %d", &n, &x0, &y0, &t);
    FO(z,0,n) {
        int xs, ys, xe, ye;
        scanf("%d %d %d %d", &xs, &ys, &xe, &ye);
        if (xs == xe) {
            if (ys > ye) swap(ys,ye);
            FO(i,ys,ye) {
                rd[i][xs][3] = true;
            }
            FO(i,ys+1,ye+1) {
                rd[i][xs][1] = true;
            }
        } else {
            if (xs > xe) swap(xs, xe);
            FO(i,xs,xe) {
                rd[ys][i][2] = true;
            }
            FO(i,xs+1,xe+1) {
                rd[ys][i][0] = true;
            }
        }
    }
    FO(i,0,4) v.emplace_back(y0, x0, i, 0);
    FO(z,0,t) {
        int d; char c;
        scanf("%d %c", &d, &c);
        int edir = -1;
        if (c == 'N') edir = 3;
        else if (c == 'S') edir = 1;
        else if (c == 'E') edir = 2;
        else edir = 0;
        memset(seen, false, sizeof seen);
        queue<tuple<int,int,int,int,int> > q;
        for (auto p : v) {
            int y, x, dr, ct;
            tie(y,x,dr,ct) = p;
            seen[y][x][d][dr][ct] = true;
            q.emplace(y,x,d,dr,ct);
        }
        while (sz(q)) {
            auto f = q.front(); q.pop();
            int y, x, dst, dr, ct; tie(y, x, dst, dr,ct) = f;
            //printf("(%d,%d): dst=%d, dr=%d, ct=%d\n", y, x, dst, dr, ct);
            if (ct == 1) {
                // can turn
                FO(ndr,0,4) if (ndr != (dr^2)) {
                    //printf("?%d,%d,%d\n", y, x, ndr);
                    if (rd[y][x][ndr]) {
                        //printf("??%d,%d,%d\n", y, x, ndr);
                        if (!seen[y][x][dst][ndr][0]) {
                            seen[y][x][dst][ndr][0] = true;
                            q.emplace(y, x, dst, ndr, 0);
                        }
                    }
                }
            } else if (dst != 0) {
                if (rd[y][x][dr]) {
                    int ny = y+dy[dr], nx = x+dx[dr];
                    int ndst = dst-1;
                    if (!seen[ny][nx][ndst][dr][1]) {
                        seen[ny][nx][ndst][dr][1] = true;
                        q.emplace(ny,nx,ndst,dr,1);
                    }
                }
            }
        }
        v.clear();
        FO(y,0,55) FO(x,0,55) FO(ct,0,2) {
            if (seen[y][x][0][edir][ct]) {
                v.emplace_back(y, x, edir, ct);
            }
        }
    }

    vector<pair<int,int> > ans;
    for (auto p : v) {
        int y, x, dr, ct;
        tie(y,x,dr,ct) = p;
        ans.emplace_back(x, y);
    }
    sort(ans.begin(), ans.end());
    FO(i,0,sz(ans)) if (!i || ans[i] != ans[i-1]) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }

    return 0;
}

Compiler output:
a.cc:12:12: error: 'int y0' redeclared as different kind of entity
   12 | int n, x0, y0, t;
      |            ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:256:1: note: previous declaration 'double y0(double)'
  256 | __MATHCALL (y0,, (_Mdouble_));
      | ^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::tuple<int, int, int, int>; _Args = {double (&)(double) noexcept, int&, int&, int}; _Tp = std::tuple<int, int, int, int>]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::tuple<int, int, int, int>; _Args = {double (&)(double) noexcept, int&, int&, int}; _Tp = std::tuple<int, int, int, int>; allocator_type = std::allocator<std::tuple<int, int, int, int> >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {double (&)(double) noexcept, int&, int&, int}; _Tp = std::tuple<int, int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int, int> >; reference = std::tuple<int, int, int, int>&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:44:29:   required from here
   44 |     FO(i,0,4) v.emplace_back(y0, x0, i, 0);
      |               ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'std::tuple<int, int, int, int>::tuple(double (&)(double) noexcept, int&, int&, int)'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:1646:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int}]'
 1646 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1646:9: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/tuple:1634:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int}]'
 1634 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1634:9: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/tuple:1623:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int}]'
 1623 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1623:9: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/tuple:1611:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<const _UElements& ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int}]'
 1611 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1611:9: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/tuple:1603:9: note: candidate: 'template<class _Alloc> std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, std::tuple< <template-parameter-1-1> >&&) [with _Elements = {int, int, int, int}]'
 1603 |         tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1603:9: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/tuple:1598:9: note: candidate: 'template<class _Alloc> std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple< <template-parameter-1-1> >&) [with _Elements = {int, int, int, int}]'
 1598 |         tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
      |         ^~~~~
/usr/include/c++/14/tuple:1598:9: note:   candidate expects 3 arguments, 4 provided
/usr/include/c++/14/tuple:1591:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int}]'
 1591 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1591:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1588:55: error: no type named 'type' in 'struct std::enable_if<false, bool>'
 1588 |                _ExplicitCtor<_Valid, _UElements...> = false>
      |                                                       ^~~~~
/usr/include/c++/14/tuple:1581:9: note: candidate: 'template<class _Alloc, class ... _UElements, bool _Valid, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...) [with _UElements = _Alloc; bool _Valid = {_UElements ...}; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<_UElements ...>(), bool>::type <anonymous> = _Valid; _Elements = {int, int, int, int}]'
 1581 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1581:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/tuple:1579:55: error: no type named 'type' in 'struct std::enable_if<false, bool>'
 1579 |                _ImplicitCtor<_Valid, _UElements...> = true>
      |                                                       ^~~~
/usr/include/c++/14/tuple:1573:9: note: candidate: 'template<class _Alloc, bool _NotEmpty, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_explicitly_constructible<const int&, const int&, const int&, const int&>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const _Elements& ...) [with bool _NotEmpty = _Alloc; typename std::enable_if<_TCC<_Valid>::__is_explicitly_constructible<const _Elements& ...>(), bool>::type <anonymous> = _NotEmpty; _Elements = {int, int, int, int}]'
 1573 |         tuple(allocator_arg_t __tag, const _Alloc& __a,
      |         ^~~~~
/usr/include/c++/14/tuple:1573:9: note:   candidate expects 6 arguments, 4 provided
/usr/include/c++/14/tuple:1565:9: note: candidate: 'template<class _Alloc, bool _NotEmpty, typename std::enable_if<std::tuple<int, int, int, int>::_TCC<_Valid>::__is_implicitly_constructible<const int&, const int&, const int&, const int&>(), bool>::type <anonymous> > std::tuple< <template-parameter-1-1> >::tuple(std::allocator_arg_t, const _Alloc&, const _Elements& ...) [with bool _NotEmpty = _Alloc; typename std::enable_if<_TCC<_Valid>::__is_implicitly_constructible<const _Elements& ...>(), bool>::type <anonymous> = _NotEmpty; _Elements = {int, int, int, int}]'
 1565 |         tuple(allocator_arg_t __tag, cons