Submission #379968

# Submission time Handle Problem Language Result Execution time Memory
379968 2021-03-19T20:26:23 Z PedroBigMan Patkice (COCI20_patkice) C++14
50 / 50
1 ms 512 KB
/*
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; vector<vector<ll> > d;

void DFS(ll x, ll y)
{
	if(visited[x][y]) {return;}
	visited[x][y]=true;
	if(c[x][y]=='.' || c[x][y]=='o' || c[x][y]=='x') {return;}
	if(c[x][y]=='<') {d[x][y-1]=d[x][y]+1; DFS(x,y-1);}
	if(c[x][y]=='>') {d[x][y+1]=d[x][y]+1; DFS(x,y+1);}
	if(c[x][y]=='^') {d[x-1][y]=d[x][y]+1; DFS(x-1,y);}
	if(c[x][y]=='v') {d[x+1][y]=d[x][y]+1; 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('z');} REP(i,0,N) {c.pb(xx);}
	vector<ll> xxxx; REP(i,0,M) {xxxx.pb(N+M);} REP(i,0,N) {d.pb(xxxx);}
	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);}
	vector<pair<ll,char> > poss;
	REP(i,0,N) {REP(j,0,M) {visited[i][j]=false; d[i][j]=N*M+1LL;}}
	d[init.ff][init.ss]=0LL; c[init.ff][init.ss]='^'; DFS(init.ff,init.ss);
	if(visited[end.ff][end.ss]) {poss.pb(mp(d[end.ff][end.ss],'N'));}
	REP(i,0,N) {REP(j,0,M) {visited[i][j]=false; d[i][j]=N*M+1LL;}}
	d[init.ff][init.ss]=0LL; c[init.ff][init.ss]='>'; DFS(init.ff,init.ss);
	if(visited[end.ff][end.ss]) {poss.pb(mp(d[end.ff][end.ss],'E'));}
	REP(i,0,N) {REP(j,0,M) {visited[i][j]=false; d[i][j]=N*M+1LL;}}
	d[init.ff][init.ss]=0LL; c[init.ff][init.ss]='v'; DFS(init.ff,init.ss);
	if(visited[end.ff][end.ss]) {poss.pb(mp(d[end.ff][end.ss],'S'));}
	REP(i,0,N) {REP(j,0,M) {visited[i][j]=false; d[i][j]=N*M+1LL;}}
	d[init.ff][init.ss]=0LL; c[init.ff][init.ss]='<'; DFS(init.ff,init.ss);
	if(visited[end.ff][end.ss]) {poss.pb(mp(d[end.ff][end.ss],'W'));}
	sort(whole(poss));
	if(poss.size()>0) {cout<<":)"<<endl<<poss[0].ss<<endl; return 0;}
	cout<<":("<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct