Submission #515712

# Submission time Handle Problem Language Result Execution time Memory
515712 2022-01-19T14:20:20 Z Hacv16 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 344 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 115;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int VAR[4] = {-1, 1, 0, 0};

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()

int n, m, dx, dy, ix, iy;
map<char, pii> dir;
char s[MAX][MAX];

void setIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
}

int dfs(int x, int y){
    if(s[x][y] == 'x') return 0;
    if(s[x][y] == '.' || s[x][y] == 'o') return INF;

    int nx = x + dir[s[x][y]].fr, ny = y + dir[s[x][y]].sc;

    return min(dfs(nx, ny) + 1, INF);
}

int main(){
    setIO();

    memset(s, '.', sizeof(s));
    dir['^'] = {-1, 0}; dir['v'] = {1, 0};
    dir['<'] = {0, -1}; dir['>'] = {0, 1}; 

    cin >> n >> m;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> s[i][j];

            if(s[i][j] == 'o') 
                dx = i, dy = j;
        }
    }

    pair<int, char> ans = {INF, 'Z'};

    ans = min(ans, {dfs(dx + 1, dy), 'S'});
    ans = min(ans, {dfs(dx - 1, dy), 'N'});
    ans = min(ans, {dfs(dx, dy + 1), 'E'});
    ans = min(ans, {dfs(dx, dy - 1), 'W'});

    if(ans.fr == INF) cout << ":(" << '\n';
    else cout << ":)" << '\n' << ans.sc << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 328 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 0 ms 204 KB Output is correct