Submission #1148960

#TimeUsernameProblemLanguageResultExecution timeMemory
1148960arsen23Nautilus (BOI19_nautilus)C++20
100 / 100
95 ms812 KiB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define F first
#define S second
#define in insert

using namespace std;
typedef long long ll;

typedef unsigned long long ull;

const int N = 1e6 + 123;

const int P = 320;

const int inf = 1e9 + 7;

ll n, m, k;

char ct[505][505];

bitset <505> a[N], b[N], c[N];

string s;

void salemkhan() {
	cin >> n >> m >> k;

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

			if(ct[i][j] == '.') {
				a[i][j] = 1;

				b[i][j] = 1;
			}
		}
	}

	cin >> s;

	for(auto x : s) {
		if(x == 'N') {
			for(int i = 1; i < n; i++) {
				b[i] = b[i + 1];

				b[i] &= a[i];
			}

			b[n] = 0;
		}

		else if(x == 'S') {
			for(int i = n; i >= 2; i--) {
				b[i] = b[i - 1];

				b[i] &= a[i];
			}

			b[1] = 0;
		}

		else if(x == 'E') {
			for(int i = 1; i <= n; i++) {
				b[i] <<= 1;

				b[i] &= a[i];
			}
		}

		else if(x == 'W') {
			for(int i = 1; i <= n; i++) {
				b[i] >>= 1;

				b[i] &= a[i];

				b[i][m] = 0;
			}
		}

		else {
            c[n + 1] = 0;

			for(int i = 1; i <= n; i++) c[i] = 0, c[i] = b[i];

			for(int i = 1; i <= n; i++) {
				b[i] = ((b[i] >> 1) |  (b[i] << 1));

				b[i] |= c[i - 1];

				b[i] |= c[i + 1];
			}
		}

		for(int i = 1; i <= n; i++) b[i] &= a[i];
	}

	ll ans = 0;

	for(int i = 1; i <= n; i++) {
		ans += b[i].count();
	}
	cout << ans << '\n';
}

// 28 37 48 49 55 56 57 58 67 9

// 9 + 1 +

int main() {

    //freopen("knight.in",   "r", stdin);

    //freopen("knight.out", "w", stdout);

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    ll tt = 1;

    //cin >> tt;

    while(tt--) {
        salemkhan();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...