Submission #366381

# Submission time Handle Problem Language Result Execution time Memory
366381 2021-02-14T06:13:21 Z kartel Patkice (COCI20_patkice) C++14
50 / 50
1 ms 384 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
using namespace std;
typedef long long ll;
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long double ld;
typedef unsigned long long ull;
typedef short int si;

const int N = 150;

int mp[300];
char cn[6];
int steps[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int n, m;
char c[N][N];
bool mrk[N][N], fnd;
int ans = 1e9, cd;

void go(int x, int y, int cnt, int cc) {
    if (x < 1 || y < 1 || x > n || y > m || mrk[x][y])
        return;

    if (c[x][y] == 'x') {
        if (cnt < ans || (cnt == ans && cn[cc] < cn[cd])) {
            ans = cnt;
            cd = cc;
        }
        return;
    }

    if (c[x][y] == '.' || c[x][y] == 'o')
        return;

    mrk[x][y] = 1;

    go(x + steps[mp[c[x][y]]][0], y + steps[mp[c[x][y]]][1], cnt + 1, cc);

    mrk[x][y] = 0;
}

int main()
{
//    mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());;
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	in("product.in");
//	out("product.out");
//    in("input.txt");
//    out("output.txt");

//    clock_t tStart = clock();
    mp['>'] = 0;
    mp['<'] = 1;
    mp['v'] = 2;
    mp['^'] = 3;
    cn[0] = 'E';
    cn[1] = 'W';
    cn[2] = 'S';
    cn[3] = 'N';

    cin >> n >> m;
    int sx, sy;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> c[i][j];

            if (c[i][j] == 'o')
                sx = i, sy = j;
        }
    }

    for (int p = 0; p < 4; p++) {
        int cx = sx + steps[p][0];
        int cy = sy + steps[p][1];

        fnd = 0;

        go(cx, cy, 1, p);
    }

    if (ans != 1e9)
        return void(cout << ":)" << el << cn[cd]), 0;

    cout << ":(";
}

Compilation message

patkice.cpp: In function 'void go(int, int, int, int)':
patkice.cpp:57:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   57 |     go(x + steps[mp[c[x][y]]][0], y + steps[mp[c[x][y]]][1], cnt + 1, cc);
      |                     ~~~~~~^
patkice.cpp:57:54: warning: array subscript has type 'char' [-Wchar-subscripts]
   57 |     go(x + steps[mp[c[x][y]]][0], y + steps[mp[c[x][y]]][1], cnt + 1, cc);
      |                                                ~~~~~~^
patkice.cpp: In function 'int main()':
patkice.cpp:95:13: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |         int cy = sy + steps[p][1];
      |             ^~
patkice.cpp:94:13: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   94 |         int cx = sx + steps[p][0];
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 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