Submission #366401

#TimeUsernameProblemLanguageResultExecution timeMemory
366401VimmerPatkice (COCI20_patkice)C++14
50 / 50
1 ms492 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("-O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-Ofast")

#define N 100500
#define NN 205000
#define PB push_back
#define endl '\n'
#define pri(x) cout << x << endl
#define _ << " " <<
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define M ll(1e9 + 7)
#define F first
#define S second

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

bool mk[105][105];

int len, n, m;

string s[105];

void rec(int x, int y)
{
    len++;

    if (x < 0 || y < 0 || x == n || y == m || mk[x][y] || s[x][y] == '.')
    {
        len = 1e9;

        return;
    }

    mk[x][y] = 1;

    if (s[x][y] == 'x') return;

    if (s[x][y] == '>') rec(x, y + 1);
      else if (s[x][y] == '<') rec(x, y - 1);
        else if (s[x][y] == 'v') rec(x + 1, y);
            else rec(x - 1, y);
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    freopen("1.in", "r", stdin);

    cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> s[i];

    int xs, ys;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (s[i][j] == 'o') {xs = i; ys = j;}

    int cur = 1e9;

    char c;

    rec(xs, ys + 1);

    if (len < cur)
    {
        cur = len;

        c = 'E';
    }

    memset(mk, 0, sizeof mk);

    len = 0;

    rec(xs - 1, ys);

    if (len < cur)
    {
        cur = len;

        c = 'N';
    }

    memset(mk, 0, sizeof mk);

    len = 0;

    rec(xs + 1, ys);

    if (len < cur)
    {
        cur = len;

        c = 'S';
    }

    memset(mk, 0, sizeof mk);

    len = 0;

    rec(xs, ys - 1);

    if (len < cur)
    {
        cur = len;

        c = 'W';
    }

    if (cur == 1e9)
    {
        pri(":(");
    }
    else
    {
        pri(":)");

        pri(c);
    }
}

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:78:8: warning: 'ys' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |     rec(xs, ys + 1);
      |     ~~~^~~~~~~~~~~~
patkice.cpp:104:8: warning: 'xs' may be used uninitialized in this function [-Wmaybe-uninitialized]
  104 |     rec(xs + 1, ys);
      |     ~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...