Submission #1016055

# Submission time Handle Problem Language Result Execution time Memory
1016055 2024-07-07T10:33:13 Z vjudge1 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 444 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 105;
int n, m, sx, sy, ex, ey;
char mat[N][N];

int dfs(int x, int y, int d = 1){
    if (x < 1 or y < 1 or x > n or y > m) return 1e9;

    if (mat[x][y] == 'x') return d;
    if (mat[x][y] == '.' or mat[x][y] == 'o') return 1e9;

    if (mat[x][y] == '>') return dfs(x, y + 1, d + 1);
    if (mat[x][y] == '<') return dfs(x, y - 1, d + 1);
    if (mat[x][y] == 'v') return dfs(x + 1, y, d + 1);
    if (mat[x][y] == '^') return dfs(x - 1, y, d + 1);
}

int main(){
    // E N S W

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

            if (mat[i][j] == 'o')
                sx = i, sy = j;
            if (mat[i][j] == 'x')
                ex = i, ey = j;
        }
    }

    vector<pair<int, char>> vec;
    vec.push_back({dfs(sx, sy + 1), 'E'});
    vec.push_back({dfs(sx - 1, sy), 'N'});
    vec.push_back({dfs(sx + 1, sy), 'S'});
    vec.push_back({dfs(sx, sy - 1), 'W'});

    sort(vec.begin(), vec.end());
    if (vec[0].first != 1e9){
        cout << ":)" << endl;
        cout << vec[0].second << endl;
    }
    else
        cout << ":(" << endl;
}

Compilation message

patkice.cpp: In function 'int dfs(int, int, int)':
patkice.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct