-
-
Save theortsac/7c466cc739879c0b06e27202f524ce56 to your computer and use it in GitHub Desktop.
Solução para Tesouro OBI 2023 F3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
char r[1001][1001]; | |
bool v[1001][1001]; | |
int p, m; | |
int f(int i, int j) { | |
if (r[i][j] == 'X') return p; | |
if (v[i][j]) return 0; | |
v[i][j] = 1; | |
int l = i, c = j; | |
if (r[i][j] == 'N') l -= 1; | |
else if (r[i][j] == 'S') l += 1; | |
else if (r[i][j] == 'L') c += 1; | |
else if (r[i][j] == 'O') c -= 1; | |
if ((l < 1) or (l > m) or (c < 1) or (c > m)) return -1; | |
p++; | |
return f(l, c); | |
} | |
int main() { | |
cin >> m; | |
for (int i = 1; i <= m; i++) { | |
for (int j = 1; j <= m; j++) { | |
cin >> r[i][j]; | |
} | |
} | |
int a, b; | |
cin >> a >> b; | |
cout << f(a, b) << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment