Submission #784358

#TimeUsernameProblemLanguageResultExecution timeMemory
784358raysh07Nautilus (BOI19_nautilus)C++17
66 / 100
1067 ms852 KiB
#include <bits/stdc++.h>
using namespace std;
#define INF (int)1e18

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve()
{
	int n, m, q; cin >> n >> m >> q;
	vector <string> a(n);
	for (auto &x : a) cin >> x;

	string s; cin >> s;
	vector<vector<bool>> dp(n, vector<bool>(m, false));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (a[i][j] == '.') dp[i][j] = true;
		}
	}

	for (auto &x : s){
		vector<vector<bool>> ndp(n, vector<bool>(m, false));

		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
			    if (a[i][j] == '#') continue;
				if (i != 0 && (x == 'S' || x == '?') && dp[i - 1][j]) ndp[i][j] = true;
				if (i != n - 1 && (x == 'N' || x == '?') && dp[i + 1][j]) ndp[i][j] = true;
				if (j != 0 && (x == 'E' || x == '?') && dp[i][j - 1]) ndp[i][j] = true;
				if (j != m - 1 && (x == 'W' || x == '?') && dp[i][j + 1]) ndp[i][j] = true;
			}
		}

		if (x == 'N') x = 'S';
		else if (x == 'S') x = 'N';
		else if (x == 'E') x = 'W';
		else if (x == 'W') x = 'E';

		dp = ndp;
	}

// 	reverse(s.begin(), s.end());
// 	for (auto &x : s){
// 		vector<vector<bool>> ndp(n, vector<bool>(m, false));

// 		for (int i = 0; i < n; i++){
// 			for (int j = 0; j < m; j++){
// 			    if (a[i][j] == '#') continue;
// 				if (i != 0 && (x == 'S' || x == '?') && dp[i - 1][j]) ndp[i][j] = true;
// 				if (i != n - 1 && (x == 'N' || x == '?') && dp[i + 1][j]) ndp[i][j] = true;
// 				if (j != 0 && (x == 'E' || x == '?') && dp[i][j - 1]) ndp[i][j] = true;
// 				if (j != m - 1 && (x == 'W' || x == '?') && dp[i][j + 1]) ndp[i][j] = true;
// 			}
// 		}

// 		if (x == 'N') x = 'S';
// 		else if (x == 'S') x = 'N';
// 		else if (x == 'E') x = 'W';
// 		else if (x == 'W') x = 'E';

// 		dp = ndp;
// 	}

	int ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			ans += dp[i][j];
		}
	}

	cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;

   // freopen("in",  "r", stdin);
   // freopen("out", "w", stdout);

  //  cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...