답안 #707451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707451 2023-03-09T03:04:34 Z GudStonks Patkice (COCI20_patkice) C++17
30 / 50
1 ms 340 KB
#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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Incorrect 0 ms 340 KB Output isn't correct
12 Halted 0 ms 0 KB -