Submission #707451

#TimeUsernameProblemLanguageResultExecution timeMemory
707451GudStonksPatkice (COCI20_patkice)C++17
30 / 50
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ft first #define sd second ll n, m; char ch[105][105]; pair<ll, ll>p[105][105], s, f; const int dirx[4] = {0, 1, 0, -1}; const int diry[4] = {1, 0, -1, 0}; char rec(pair<ll, ll>x, pair<ll, ll> pr = {-1ll, -1ll}){ if(x == s){ if(pr.ft == x.ft - 1) return 'N'; else if(pr.ft == x.ft + 1) return 'S'; else if(pr.sd == x.sd - 1) return 'W'; else return 'E'; } return rec(p[x.ft][x.sd], x); } void fun(){ cin>>n>>m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin>>ch[i][j]; if(ch[i][j] == 'o') s = {i, j}; if(ch[i][j] == 'x') f = {i, j}; } } queue<pair<ll, ll> >q; q.push({s.ft + 1, s.sd}); q.push({s.ft - 1, s.sd}); q.push({s.ft, s.sd + 1}); q.push({s.ft, s.sd - 1}); p[s.ft + 1][s.sd] = {s.ft, s.sd}; p[s.ft - 1][s.sd] = {s.ft, s.sd}; p[s.ft][s.sd + 1] = {s.ft, s.sd}; p[s.ft][s.sd - 1] = {s.ft, s.sd}; p[s.ft][s.sd] = make_pair(-1ll, -1ll); while(!q.empty()){ auto v = q.front(); q.pop(); ll x = v.ft, y = v.sd; int i = (ch[v.ft][v.sd] == '^' ? 3 : (ch[v.ft][v.sd] == '<' ? 2 : (ch[v.ft][v.sd] == 'v' ? 1 : (ch[v.ft][v.sd] == '>' ? 0 : -1)))); if( i == -1 || p[x + dirx[i]][y + diry[i]] != make_pair(0ll, 0ll)) continue; p[x + dirx[i]][y + diry[i]] = {x, y}; q.push({x + dirx[i], y + diry[i]}); } if(p[f.ft][f.sd] == make_pair(0ll, 0ll)){ cout<<":(\n"; return; } cout<<":)\n"<<rec(f); } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int ttt = 1; //cin>>ttt; while(ttt--)fun(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...