Submission #366401

# Submission time Handle Problem Language Result Execution time Memory
366401 2021-02-14T06:40:44 Z Vimmer Patkice (COCI20_patkice) C++14
50 / 50
1 ms 492 KB
#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

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 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 492 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