답안 #660781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660781 2022-11-23T08:30:16 Z Kenpar Patkice (COCI20_patkice) C++17
0 / 50
1 ms 212 KB
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define endl '\n'

const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 2 * 1e5;

int n,m;

char arr[101][101];
map<pair<int,int>, bool> visited;
int DFS(int i, int j){
	if(i < 0 || i >= n) return -101*102;
	if(j < 0 || j >= m) return -101*102;

	if(visited[{i,j}]) return -101*102;

	visited[{i,j}] = true;
	if(arr[i][j] == '.' || arr[i][j] == 'o') return -101*102;

	if(arr[i][j] == 'x') return 0;

	if(arr[i][j] == 'v') return DFS(i+1, j) + 1;
	if(arr[i][j] == '^') return DFS(i-1, j) + 1;
	if(arr[i][j] == '>') return DFS(i, j+1) + 1;
	if(arr[i][j] == '<') return DFS(i, j-1) + 1;

}

void solve(){
	cin>>n>>m;

	pair<int,int> start;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin>>arr[i][j];

			if(arr[i][j] == 'o') start = {i,j};
		}
	}

	vector<pair<int, char>> ans;
	int temp = DFS(start.first + 1, start.second);
	if(temp > -1){
		ans.push_back({temp, 'S'});
	}

	visited = map<pair<int,int>, bool>();
	temp = DFS(start.first - 1, start.second);
	if(temp > -1){
		ans.push_back({temp, 'N'});
	}

	visited = map<pair<int,int>, bool>();

	temp = DFS(start.first, start.second - 1);

	if(temp > -1){
		ans.push_back({temp, 'W'});
	}


	visited = map<pair<int,int>, bool>();
	temp = DFS(start.first, start.second + 1);
	if(temp > -1){
		ans.push_back({temp, 'E'});
	}

	sort(ans.begin(), ans.end());

	if(ans.size() == 0){
		cout<<":(";
		return;
	}else{
		cout<<":)\n"<<ans[0].second;
	}
}


int main()
{
    cin.tie(NULL);
    ios::sync_with_stdio(NULL);
    int t = 1;

    //cin>>t;
    int temp = t;
    while(t--){
        //cout<<"Case #"<<temp - t<<" > "<<endl;
        solve();

        cout<<endl;
    }

    cout.flush();
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:90:9: warning: unused variable 'temp' [-Wunused-variable]
   90 |     int temp = t;
      |         ^~~~
patkice.cpp: In function 'int DFS(int, int)':
patkice.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
   31 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -