Submission #359923

# Submission time Handle Problem Language Result Execution time Memory
359923 2021-01-27T10:19:48 Z MrRobot_28 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 384 KB
#include<bits/stdc++.h>
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    char A[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;
            }
        }
    }
    vector <int> dx, dy;
    vector <char> vec;
    dx = {0, -1, 1, 0};
    dy = {1, 0, 0, -1};
    vec = {'E', 'N', 'S', 'W'};
    vector <char> vec1;
    vec1 = {'>', '^', 'v', '<'};
    char p1 = ' ';
    int ans = 1e9;
    for(int i = 0; i < 4; i++)
    {
        pair <int, int> st = {stx + dx[i], sty + dy[i]};
        bool fl = 0;
        int cnt = 0;
        while(true)
        {
            cnt++;
            if(st.first < 0 || st.second < 0 || st.first >= n || st.second >= m)
            {
                break;
            }
            if(A[st.first][st.second] == 'x')
            {
                fl = 1;
                break;
            }
            if(A[st.first][st.second] == '.' || A[st.first][st.second] == 'o')
            {
                break;
            }
            for(int j = 0; j < 4; j++)
            {
                if(A[st.first][st.second] == vec1[j])
                {
                    st.first += dx[j];
                    st.second += dy[j];
                    break;
                }
            }
        }
     //   cout << st.first << " " << st.second << "\n";
        if(fl && cnt < ans)
        {
            ans = cnt;
            p1 = vec[i];
        }
    }
    if(p1 == ' ')
    {
    cout << ":(";
    }
    else
    {
        cout << ":)\n";
        cout << p1;
    }
    return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:35:35: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |         pair <int, int> st = {stx + dx[i], sty + dy[i]};
patkice.cpp:35:48: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |         pair <int, int> st = {stx + dx[i], sty + dy[i]};
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct