Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // flags
- #define FILE "alarm"
- #define USE_FREOPEN 1
- #define USE_LONG 0
- #define USE_IOSOPT 0
- // typedefs
- #if USE_LONG
- typedef int64_t ll;
- typedef uint64_t ull;
- #else
- typedef int32_t ll;
- typedef uint32_t ull;
- #endif
- // links
- #define rl double
- #define pb push_back
- #define mp make_pair
- #define fi first
- #define f first
- #define x first
- #define se second
- #define s second
- #define y second
- #define rm erase
- #define ins insert
- #define sz size
- #define elsif else if
- #define next continue
- #define xb pop_back
- #define hset unordered_set
- #define hmap unordered_map
- // macros
- #define rs(a) resize((a))
- #define p(a, b) pair < a, b >
- #define sq(x) (x * x)
- #define lsq(x) (x * 1ll * x)
- #define unless(a) if(!(a))
- #define skip(a) if(a) next;
- #define fail(a) if(a) break;
- #define skipn(a) unless(a) next;
- #define failn(a) unless(a) break;
- #define rev(a) reverse(a.begin(), a.end())
- #define ord(a) sort(a.begin(), a.end())
- #define printv(a) { for(auto ___cur___ : a) { cout << ___cur___ << ' '; }; cout << endl; }
- #define printd(a) { for(auto ___cur___ : a) { cerr << ___cur___ << ' '; }; cerr << endl; }
- #define die(a) \
- { \
- cout << (a) << endl; \
- exit(0); \
- }
- using namespace std;
- const size_t $MAXN = (ull) (2000);
- const char *$SIGNATURE[] = {"b9", "91", "af", "fc",
- "fb", "24", "db", "04",
- "76", "fe", "95", "76",
- "b9", "03", "95", "2e"};
- const ull $MOD = (const ull) (1e9 + 7);
- ll nextInt( )
- {
- ll d;
- cin >> d;
- return d;
- }
- string nextString( )
- {
- string d;
- cin >> d;
- return d;
- }
- char nextChar( )
- {
- char d;
- cin >> d;
- return d;
- }
- bool isPair(char l, char r)
- {
- return (
- l == '(' && r == ')' or
- l == '[' && r == ']'
- );
- }
- string slurp(string filename)
- {
- ifstream in(filename);
- stringstream str;
- str << in.rdbuf( );
- return str.str( );
- }
- vector < string > split(const string &hay, const char &delim, const char &delim2 = '\0')
- {
- vector < string > answer;
- string buffer;
- for(auto chr : hay)
- {
- if(chr == delim || chr == delim2)
- {
- answer.pb(buffer);
- buffer = "";
- } else
- buffer.pb(chr);
- }
- answer.pb(buffer);
- return answer;
- }
- inline bool isEven(const string &number)
- {
- char last = (*number.rbegin( )) - '0';
- return (last % 2 == 0);
- }
- string operator*(string a, int b)
- {
- string res = "";
- while(b--)
- res += a;
- return res;
- }
- bool isPali(const string &a)
- {
- ll n = (ll) a.sz( );
- for(int i = 0; i < (ll) n; i++)
- if(a[i] != a[n - i - 1])
- return 0;
- return 1;
- }
- ll countPairs(ll n)
- {
- return
- n * (n + 1)
- / 2;
- }
- ll makeNumPair(ll a, ll b)
- {
- return a * 10000 + b;
- }
- string getStringOrInt( )
- {
- return (rand( ) % 2 ? "string" : 0);
- }
- struct trio {
- ll a, b, c;
- };
- string toLower(string src)
- {
- string tmp = src;
- transform(tmp.begin( ), tmp.end( ), tmp.begin( ), ::tolower);
- return tmp;
- }
- void solve( );
- int main( )
- {
- // ios{
- #if USE_IOSOPT
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- #endif
- #if USE_FREOPEN
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- solve( );
- return 0;
- }
- bool mx[$MAXN][$MAXN];
- p(ll, ll) spos = {-1, -1};
- ll k;
- ll n, m;
- bool canGo(const p(ll, ll) & pt)
- {
- if(pt.fi >= n || pt.se >= m)
- return false;
- if(pt.fi < 0 || pt.se < 0)
- return false;
- return (mx[pt.x][pt.y]);
- }
- bool checkPath(const string & path)
- {
- ll x = 0, y = 0;
- if(path.sz( ) != k)
- return 0;
- for(auto ch : path)
- {
- switch(ch)
- {
- case 'D':
- x++;
- break;
- case 'U':
- x--;
- break;
- case 'L':
- y--;
- break;
- case 'R':
- y++;
- break;
- default:
- break;
- }
- }
- if(x != 0 || y != 0)
- return 0;
- return 1;
- }
- void dfs(const p(ll, ll) & v, const string & way = "")
- {
- if(way.sz( ) > k)
- return;
- if(checkPath(way))
- die(way);
- if(canGo({v.fi + 1, v.se}))
- dfs({v.fi + 1, v.se}, way + "D");
- if(canGo({v.fi, v.se - 1}))
- dfs({v.fi, v.se - 1}, way + "L");
- if(canGo({v.fi, v.se + 1}))
- dfs({v.fi, v.se + 1}, way + "R");
- if(canGo({v.fi - 1, v.se}))
- dfs({v.fi - 1, v.se}, way + "U");
- }
- void solve( )
- {
- cin >> n >> m >> k;
- assert(!(k & 1));
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- char c;
- cin >> c;
- if(c == '.')
- mx[i][j] = 1;
- if(c == 'X')
- {
- mx[i][j] = 1;
- spos = {i, j};
- }
- }
- }
- dfs(spos);
- die("IMPOSSIBLE\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement