Submission #213567

# Submission time Handle Problem Language Result Execution time Memory
213567 2020-03-26T06:58:39 Z usachevd0 Nautilus (BOI19_nautilus) C++14
100 / 100
286 ms 896 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

template<typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template<typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

void debug_out()
{
    cerr << endl;
}

template<typename T1, typename... T2> void debug_out(T1 A, T2... B)
{
    cerr << ' ' << A;
    debug_out(B...);
}

#ifdef DEBUG
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 42
#endif

const int maxN = 502;
int n, m, k;
using BitSet = bitset<maxN * maxN>;
BitSet dp[2];
BitSet grid;
BitSet E, W;

signed main()
{
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> k;
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin >> s;
        for (int j = 0; j < m; ++j)
        {
            if (s[j] == '.')
            {
                grid[i * m + j] = 1;
            }
        }
    }
    E = grid;
    for (int i = 0; i < n; ++i)
        E[i * m] = 0;
    W = grid;
    for (int i = 0; i < n; ++i)
        W[i * m + m - 1] = 0;
    dp[0] = grid;
    
    string I;
    cin >> I;
    for (int l = 1; l <= k; ++l)
    {
        dp[l & 1].reset();
        char c = I[l - 1];
        if (c == 'E' || c == '?')
        {
            dp[l & 1] |= E & (dp[l & 1 ^ 1] << 1);
        }
        if (c == 'W' || c == '?')
        {
            dp[l & 1] |= W & (dp[l & 1 ^ 1] >> 1);
        }
        if (c == 'S' || c == '?')
        {
            dp[l & 1] |= grid & (dp[l & 1 ^ 1] << m);
        }
        if (c == 'N' || c == '?')
        {
            dp[l & 1] |= grid & (dp[l & 1 ^ 1] >> m);
        }
    }
    cout << dp[k & 1].count() << '\n';

    return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:81:36: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             dp[l & 1] |= E & (dp[l & 1 ^ 1] << 1);
                                  ~~^~~
nautilus.cpp:85:36: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             dp[l & 1] |= W & (dp[l & 1 ^ 1] >> 1);
                                  ~~^~~
nautilus.cpp:89:39: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             dp[l & 1] |= grid & (dp[l & 1 ^ 1] << m);
                                     ~~^~~
nautilus.cpp:93:39: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
             dp[l & 1] |= grid & (dp[l & 1 ^ 1] >> m);
                                     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 9 ms 640 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 9 ms 640 KB Output is correct
14 Correct 9 ms 640 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 10 ms 640 KB Output is correct
18 Correct 11 ms 640 KB Output is correct
19 Correct 11 ms 640 KB Output is correct
20 Correct 11 ms 640 KB Output is correct
21 Correct 10 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 7 ms 640 KB Output is correct
5 Correct 6 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 8 ms 640 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 9 ms 640 KB Output is correct
11 Correct 8 ms 640 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 9 ms 640 KB Output is correct
14 Correct 9 ms 640 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 10 ms 640 KB Output is correct
18 Correct 11 ms 640 KB Output is correct
19 Correct 11 ms 640 KB Output is correct
20 Correct 11 ms 640 KB Output is correct
21 Correct 10 ms 640 KB Output is correct
22 Correct 137 ms 896 KB Output is correct
23 Correct 138 ms 896 KB Output is correct
24 Correct 133 ms 896 KB Output is correct
25 Correct 131 ms 896 KB Output is correct
26 Correct 135 ms 896 KB Output is correct
27 Correct 225 ms 896 KB Output is correct
28 Correct 217 ms 896 KB Output is correct
29 Correct 212 ms 896 KB Output is correct
30 Correct 212 ms 896 KB Output is correct
31 Correct 212 ms 896 KB Output is correct
32 Correct 271 ms 896 KB Output is correct
33 Correct 280 ms 896 KB Output is correct
34 Correct 286 ms 896 KB Output is correct
35 Correct 279 ms 896 KB Output is correct
36 Correct 270 ms 896 KB Output is correct