This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 500000000LL
#define EPS 0.00000001
#define pi 3.14159
ll mod=1000000007LL;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
ll N,M; vector<vector<char> > c; vector<vector<bool> > visited;
void DFS(ll x, ll y)
{
visited[x][y]=true;
if(c[x][y]=='.' || c[x][y]=='o' || c[x][y]=='x') {return;}
if(c[x][y]=='<') {DFS(x,y-1);}
if(c[x][y]=='>') {DFS(x,y+1);}
if(c[x][y]=='^') {DFS(x-1,y);}
if(c[x][y]=='v') {DFS(x+1,y);}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>N>>M; vector<char> xx; REP(i,0,M) {xx.pb(' ');} REP(i,0,N) {c.pb(xx);}
pl init,end;
REP(i,0,N)
{
REP(j,0,M)
{
cin>>c[i][j];
if(c[i][j]=='x') {end=mp(i,j);}
else if(c[i][j]=='o') {init=mp(i,j);}
}
}
vector<bool> xxx; REP(i,0,M) {xxx.pb(false);} REP(i,0,N) {visited.pb(xxx);}
REP(i,0,N) {REP(j,0,M) {visited[i][j]=false;}}
c[init.ff][init.ss]='^'; DFS(init.ff,init.ss);
if(visited[end.ff][end.ss]) {cout<<":)"<<endl<<"N"<<endl;return 0;}
REP(i,0,N) {REP(j,0,M) {visited[i][j]=false;}}
c[init.ff][init.ss]='>'; DFS(init.ff,init.ss);
if(visited[end.ff][end.ss]) {cout<<":)"<<endl<<"E"<<endl;return 0;}
REP(i,0,N) {REP(j,0,M) {visited[i][j]=false;}}
c[init.ff][init.ss]='v'; DFS(init.ff,init.ss);
if(visited[end.ff][end.ss]) {cout<<":)"<<endl<<"S"<<endl;return 0;}
REP(i,0,N) {REP(j,0,M) {visited[i][j]=false;}}
c[init.ff][init.ss]='<'; DFS(init.ff,init.ss);
if(visited[end.ff][end.ss]) {cout<<":)"<<endl<<"W"<<endl;return 0;}
cout<<":("<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |