Submission #310453

# Submission time Handle Problem Language Result Execution time Memory
310453 2020-10-07T03:13:33 Z HynDuf Nautilus (BOI19_nautilus) C++11
100 / 100
63 ms 888 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define task "N"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 502;
int n, m, K;
string s[N], t;
bitset<N> dp[N][2], sea[N];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> m >> K;
    rep(i, 0, n - 1) cin >> s[i];
    cin >> t;
    t = '0' + t;
    rep(i, 1, n)
    {
        rep(j, 0, m - 1) dp[i][0][j] = (s[i - 1][j] == '.');
        sea[i] = dp[i][0];
    }
    rep(k, 1, K)
    {
        int p = k & 1;
        rep(i, 1, n)
        {
            dp[i][p].reset();
            if (t[k] == '?') dp[i][p] = (dp[i + 1][p ^ 1] | dp[i - 1][p ^ 1] | (dp[i][p ^ 1] << 1) | (dp[i][p ^ 1] >> 1));
            if (t[k] == 'E') dp[i][p] = (dp[i][p ^ 1] << 1);
            if (t[k] == 'W') dp[i][p] = (dp[i][p ^ 1] >> 1);
            if (t[k] == 'S') dp[i][p] = dp[i - 1][p ^ 1];
            if (t[k] == 'N') dp[i][p] = dp[i + 1][p ^ 1];
            dp[i][p] &= sea[i];
        }
    }
    int ans = 0;
    rep(i, 1, n) ans += dp[i][K & 1].count();
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 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 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 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 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 43 ms 640 KB Output is correct
23 Correct 45 ms 768 KB Output is correct
24 Correct 51 ms 768 KB Output is correct
25 Correct 43 ms 768 KB Output is correct
26 Correct 43 ms 768 KB Output is correct
27 Correct 53 ms 768 KB Output is correct
28 Correct 54 ms 768 KB Output is correct
29 Correct 54 ms 768 KB Output is correct
30 Correct 55 ms 768 KB Output is correct
31 Correct 54 ms 888 KB Output is correct
32 Correct 62 ms 768 KB Output is correct
33 Correct 62 ms 768 KB Output is correct
34 Correct 62 ms 768 KB Output is correct
35 Correct 63 ms 768 KB Output is correct
36 Correct 62 ms 640 KB Output is correct