Submission #851373

# Submission time Handle Problem Language Result Execution time Memory
851373 2023-09-19T17:06:12 Z vjudge1 Patkice (COCI20_patkice) C++17
0 / 50
1 ms 2396 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];
bool vis[MAXN][MAXN];

map <char, int> mp;
map <int, set <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;
    stx = sty = finx = finy = 0;
    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;
            } else if(matrix[i][j] == 'x') {
                finx = i;
                finy = j;
            }
        }
    }

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

        //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 {
        memset(vis, false, sizeof(vis));

        int x;
        if(yon == 0) {
            x = dfs(stx -1, sty) +1;
        } else if(yon == 1) {
            x = dfs(stx, sty -1) +1;
        } else if(yon == 2) {
            x = dfs(stx, sty +1) +1;
        } else {
            x = dfs(stx +1, sty) +1;
        }

        cerr << "\n";

        return min(int(1e9) + 7, x);
    };

    mp['E'] = 2;
    mp['N'] = 1;
    mp['S'] = 3;
    mp['W'] = 0;

    for(auto &[ch, a] : mp) {
        int gel = check(a);
        if(gel != 1e9 + 7) {
            cerr << gel << " " << ch << "\n";
            ans[gel].emplace(ch);
        }
    }

    if(ans.empty()) {
        cout << ":(";
    } else {
        cout << ":)\n";
        cout << char(*(ans.begin()->second.begin()));
    }
    
    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:41:9: warning: unused variable 'cnt' [-Wunused-variable]
   41 |     int cnt = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -