Submission #484923

# Submission time Handle Problem Language Result Execution time Memory
484923 2021-11-05T18:05:28 Z Kirill22 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 332 KB
#include<bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define fi first
#define se second

const int N = 100;
char a[N][N];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int stx, sty;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            if (a[i][j] == 'o') stx = i, sty = j;
        }
    }
    pair<int, char> ans = {(int) 1e9, 'A'};
    for (auto c : "SENW") {
        int x = stx, y = sty, dist = 0;
        if (c == 'N') x--;
        if (c == 'E') y++;
        if (c == 'W') y--;
        if (c == 'S') x++;
        while (x >= 0 && x < n && y >= 0 && y < m) {
            dist++;
            if (a[x][y] == '>') y++;
            else if (a[x][y] == '<') y--;
            else if (a[x][y] == '^') x--;
            else if (a[x][y] == 'v') x++;
            else break;
        }
        //cout << dist << " " << c << endl;
        if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] == 'x') {
            ans = min(ans, {dist, c});
        }
    }
    if (ans.se != 'A') {
        cout << ":)\n" << ans.se;
    }
    else {
        cout << ":(";
    }
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:31:24: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |         if (c == 'W') y--;
      |                       ~^~
patkice.cpp:32:24: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |         if (c == 'S') x++;
      |                       ~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 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 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 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 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct