Submission #1294645

#TimeUsernameProblemLanguageResultExecution timeMemory
1294645pragmatistNautilus (BOI19_nautilus)C++17
66 / 100
1096 ms1092 KiB
#include<bits/stdc++.h>

using namespace std;

const int N = (int)5e2+7;

int n, m, t;
char a[N][N];
bool used[N][N][2];
string s;

vector<pair<int, int> > dir[5] = {
{{-1, 0}},
{{0, 1}},
{{1, 0}},
{{0, -1}},
{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}
};

int II[256];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> t;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> a[i][j];
			if(a[i][j] == '.') {
				used[i][j][0] = 1;
			}
		}
	}
	cin >> s;
	II['N'] = 0;
	II['E'] = 1;
	II['S'] = 2;
	II['W'] = 3;
	II['?'] = 4;
	for(int w = 0; w < t; w++) {
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				if(!used[i][j][0]) {
					continue;
				}
				for(auto e : dir[II[s[w]]]) {
					int tox = e.first+i;
					int toy = e.second+j;
					if(tox<1 || tox>n || toy<1 || toy>m || a[tox][toy] == '#') {
						continue;
					}
					used[tox][toy][1] = 1;
				}				
			}
		}
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				used[i][j][0] = used[i][j][1];
				used[i][j][1] = 0;
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			ans += used[i][j][0];
		}
	}
	cout << ans;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...