Submission #601266

# Submission time Handle Problem Language Result Execution time Memory
601266 2022-07-21T14:28:28 Z nguyen31hoang08minh2003 Patkice (COCI20_patkice) C++14
50 / 50
1 ms 340 KB
/*
\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /
\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //
/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \
\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /
/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \
\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /
/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \
\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /
//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\
/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \
\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /\ \//\\//\\/ /
\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //\\  \//\\/  //
/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \/ \   \/   / \
\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /\  \  /\  /  /
/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \/   \//\\/   \
\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /\   /\\//\   /
/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \/  /  \/  \  \
\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /\ /   /\   \ /
//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\//  /\\//\  \\
/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \/ /\\//\\//\ \
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for (int i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (int i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (int i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;

template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};

typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define maxR 105
#define maxC 105
const int inf = 0X3F3F3F3F;
const short directions[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
const string ways = "^>v<", NESW = "NESW";

int r, c, shortestPath = inf;
string sea[maxR];
char result;

int DP(int x, int y) {
    static vvi dp(maxR, vi(maxC, -1));
    if (dp[x][y] < 0) {
        switch (sea[x][y]) {
        case 'x':
            dp[x][y] = 0;
            break;
        case 'o':
        case '.':
            dp[x][y] = inf;
            break;
        default:
            dp[x][y] = inf;
            fore(d, 0, 4)
                if (ways[d] == sea[x][y]) {
                    mini(dp[x][y], DP(x + directions[d][0], y + directions[d][1]) + 1);
                    break;
                }
        }
    }
    return dp[x][y];
}

int main() {
    int x = -1, y = -1;
    #ifdef LOCAL
        freopen("input.INP", "r", stdin);
    #endif // LOCAL
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);
    cin >> r >> c;
    fore(i, 0, r) {
        cin >> sea[i];
        if (x < 0) {
            fore(j, 0, c)
                if (sea[i][j] == 'o') {
                    x = i;
                    y = j;
                    break;
                }
        }
    }
    fore(d, 0, 4) {
        if (mini(shortestPath, DP(x + directions[d][0], y + directions[d][1]) + 1))
            result = NESW[d];
        if (shortestPath == DP(x + directions[d][0], y + directions[d][1]) + 1)
            mini(result, NESW[d]);
    }
    if (shortestPath >= inf)
        puts(":(");
    else
        cout << ":)\n" << result << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct