Submission #687507

# Submission time Handle Problem Language Result Execution time Memory
687507 2023-01-26T13:06:40 Z stanislavpolyn Nautilus (BOI19_nautilus) C++17
100 / 100
191 ms 924 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? a = b, 1 : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 505;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const string d = "SNEW";

int n, m, k;
char a[N][N];
string s;

bool dp[N][N], ndp[N][N];

bool valid(int x, int y) {
    return x >= 1 && y >= 1 && x <= n && y <= m && a[x][y] != '#';
}

bitset<505> b[N], nb[N];

int brute() {
    fr (i, 1, n) {
        fr (j, 1, m) {
            if (a[i][j] != '#') {
                dp[i][j] = 1;
            }
        }
    }


    fr (step, 0, sz(s) - 1) {
        int p = find(all(d), s[step]) - d.begin();

        fr (i, 1, n) {
            fr (j, 1, m) {
                if (dp[i][j]) {
                    if (p != sz(d)) {
                        if (valid(i + dx[p], j + dy[p])) {
                            ndp[i + dx[p]][j + dy[p]] = 1;
                        }
                    } else {
                        fr (cur, 0, 3) {
                            if (valid(i + dx[cur], j + dy[cur])) {
                                ndp[i + dx[cur]][j + dy[cur]] = 1;
                            }
                        }
                    }
                }
            }
        }
        fr (i, 1, n) {
            fr (j, 1, m) {
                dp[i][j] = ndp[i][j];
                ndp[i][j] = 0;
            }
        }
    }

    int ans = 0;
    fr (i, 1, n) {
        fr (j, 1, m) {
            if (dp[i][j]) {
                ans++;
            }
        }
    }
    return ans;
}

bitset<505> good[N];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> m >> k;

    fr (i, 1, n) {
        fr (j, 1, m) {
            cin >> a[i][j];
            if (a[i][j] == '.') {
                good[i][j] = 1;
            }
        }
    }

    cin >> s;

    fr (i, 1, n) {
        fr (j, 1, m) {
            if (a[i][j] == '.') {
                b[i][j] = 1;
            }
        }
    }

    fr (step, 0, sz(s) - 1) {
        if (s[step] == 'W') {
            fr (i, 1, n) {
                nb[i] = b[i] >> 1;
            }
        }
        if (s[step] == 'E') {
            fr (i, 1, n) {
                nb[i] = b[i] << 1;
            }
        }
        if (s[step] == 'N') {
            fr (i, 1, n - 1) {
                nb[i] = b[i + 1];
            }
        }
        if (s[step] == 'S') {
            rf (i, n, 2) {
                nb[i] = b[i - 1];
            }
        }
        if (s[step] == '?') {
            fr (i, 1, n) {
                nb[i] |= b[i] >> 1;
            }
            fr (i, 1, n) {
                nb[i] |= b[i] << 1;
            }
            fr (i, 1, n - 1) {
                nb[i] |= b[i + 1];
            }
            rf (i, n, 2) {
                nb[i] |= b[i - 1];
            }
        }

        fr (i, 1, n) {
            b[i] = nb[i] & good[i];
            nb[i].reset();
        }
    }

    int ans = 0;
    fr (i, 1, n) {
        ans += b[i].count();
    }
    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 88 ms 668 KB Output is correct
23 Correct 101 ms 852 KB Output is correct
24 Correct 90 ms 920 KB Output is correct
25 Correct 85 ms 916 KB Output is correct
26 Correct 83 ms 904 KB Output is correct
27 Correct 146 ms 916 KB Output is correct
28 Correct 139 ms 916 KB Output is correct
29 Correct 131 ms 916 KB Output is correct
30 Correct 129 ms 912 KB Output is correct
31 Correct 139 ms 900 KB Output is correct
32 Correct 191 ms 924 KB Output is correct
33 Correct 159 ms 912 KB Output is correct
34 Correct 161 ms 916 KB Output is correct
35 Correct 163 ms 852 KB Output is correct
36 Correct 178 ms 900 KB Output is correct