Submission #464369

# Submission time Handle Problem Language Result Execution time Memory
464369 2021-08-13T05:47:31 Z dannyboy20031204 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 332 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define double long double
using namespace std;
void db() {cerr << endl;}
template <typename T, typename ...U> void db(T a, U ...b) {
    cerr << a << ' ', db(b...);
}
const int N = 100, inf = 1e9 + 1;
int n, m;
string a[N];
int solve(int x, int y){
    int ans = 1;
    while (a[x][y] != 'x'){
        ans++;
        if (a[x][y] == '.' or a[x][y] == 'o')
            return inf;
        else if (a[x][y] == '^')
            x--;
        else if (a[x][y] == 'v')
            x++;
        else if (a[x][y] == '<')
            y--;
        else
            y++;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m;
    int x, y;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        for (int j = 0; j < m; j++)
            if (a[i][j] == 'o')
                x = i, y = j;
    }
    int ans = solve(x, y + 1);
    char d = 'E';
    if (ans > solve(x - 1, y))
        ans = solve(x - 1, y), d = 'N';
    if (ans > solve(x + 1, y))
        ans = solve(x + 1, y), d = 'S';
    if (ans > solve(x, y - 1))
        ans = solve(x, y - 1), d = 'W';
    if (ans == inf){
        cout << ":(";
    }
    else{
        cout << ":)\n";
        cout << d;
    }
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:43:20: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |     if (ans > solve(x - 1, y))
      |               ~~~~~^~~~~~~~~~
patkice.cpp:43:20: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 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 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 204 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 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 204 KB Output is correct