Submission #511509

# Submission time Handle Problem Language Result Execution time Memory
511509 2022-01-16T00:52:09 Z KoD Patkice (COCI20_patkice) C++17
50 / 50
1 ms 332 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

template <class F> struct RecLambda : private F {
    explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

int main() {
    int H, W;
    std::cin >> H >> W;
    vector<char> grid(H * W);
    for (auto& x : grid) {
        std::cin >> x;
    }
    int src = 0, dst = 0;
    while (grid[src] != 'o') src += 1;
    while (grid[dst] != 'x') dst += 1;
    vector<int> dist(H * W, -1);
    dist[dst] = 0;
    const auto dfs = RecLambda([&](auto&& dfs, const int u) -> int {
        if (dist[u] >= 0) return dist[u];
        if (grid[u] == '<') return dist[u] = dfs(u - 1) + 1;
        if (grid[u] == '>') return dist[u] = dfs(u + 1) + 1;
        if (grid[u] == '^') return dist[u] = dfs(u - W) + 1;
        if (grid[u] == 'v') return dist[u] = dfs(u + W) + 1;
        return H * W;
    });
    pair<int, char> ans(H * W, 'Z');
    ans = std::min(ans, std::make_pair(dfs(src - 1), 'W'));
    ans = std::min(ans, std::make_pair(dfs(src + 1), 'E'));
    ans = std::min(ans, std::make_pair(dfs(src - W), 'N'));
    ans = std::min(ans, std::make_pair(dfs(src + W), 'S'));
    if (ans.first == H * W) {
        std::cout << ":(\n";
    } else {
        std::cout << ":)\n";
        std::cout << ans.second << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 284 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 204 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 292 KB Output is correct