Submission #851391

# Submission time Handle Problem Language Result Execution time Memory
851391 2023-09-19T17:24:19 Z vjudge1 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 1624 KB
//author:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
const int MAXN = 1000 + 5;

char matrix[MAXN][MAXN];

set <pair <int, char>> ans;

char get() {
    char ch; 
    cin >> ch;

    return ch;
}

void solve() {
    memset(matrix, '.', sizeof (matrix));
    int n, m; 
    cin >> n >> m;

    int stx, sty, finx, finy;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            matrix[i][j] = get();
            if(matrix[i][j] == 'o') {
                stx = i;
                sty = j;
            }
        }
    }

    int cnt = 0;
    function <int(int, int)> dfs = [&](int x, int y) -> int {
        if(matrix[x][y] == '.' || matrix[x][y] == 'o' || x == 0 || x == n +1 || y == 0 || y == m +1) 
            return int(1e9 + 7);
		if(matrix[x][y] == 'x') 
			return 0;

        //cerr << x << " " << y << "\n";
        
        if(matrix[x][y] == '>') {
            return dfs(x, y +1) +1;
        } else if(matrix[x][y] == 'v') {
            return dfs(x +1, y) +1;
        } else if(matrix[x][y] == '<') {
            return dfs(x, y -1) +1;
        } else if(matrix[x][y] == '^') {
            return dfs(x -1, y) +1;
        }

        return 0;
    };

    auto check = [&](int yon) -> int {
        int x = 1e9 + 7;
        if(yon == 0) {
            x = dfs(stx -1, sty);
        } else if(yon == 1) {
            x = dfs(stx, sty -1);
        } else if(yon == 2) {
            x = dfs(stx, sty +1);
        } else {
            x = dfs(stx +1, sty);
        }

        return min(int(1e9) + 7, x);
    };
	
	ans.emplace(check(2), 'E');
	ans.emplace(check(0), 'N');
	ans.emplace(check(3), 'S');
	ans.emplace(check(1), 'W');

    if(ans.begin()->first == int(1e9 + 7)) {
        cout << ":(";
    } else {
        cout << ":)\n";
        cout << char(ans.begin()->second);
    }
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    while(t--)
        solve();

    return 0;
}

Compilation message

patkice.cpp: In function 'void solve()':
patkice.cpp:24:19: warning: unused variable 'finx' [-Wunused-variable]
   24 |     int stx, sty, finx, finy;
      |                   ^~~~
patkice.cpp:24:25: warning: unused variable 'finy' [-Wunused-variable]
   24 |     int stx, sty, finx, finy;
      |                         ^~~~
patkice.cpp:35:9: warning: unused variable 'cnt' [-Wunused-variable]
   35 |     int cnt = 0;
      |         ^~~
patkice.cpp:62:20: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |             x = dfs(stx, sty -1);
      |                 ~~~^~~~~~~~~~~~~
patkice.cpp:24:9: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     int stx, sty, finx, finy;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1368 KB Output is correct
6 Correct 1 ms 1624 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1368 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1448 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1452 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1372 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1444 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct