Submission #1265822

#TimeUsernameProblemLanguageResultExecution timeMemory
1265822minggaNautilus (BOI19_nautilus)C++20
0 / 100
0 ms320 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
int n, m, k, idd[150];

pair<int, int> d[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

bitset<505> f[2][505], a[505];

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> m >> k;
	idd['N'] = 1;
	idd['S'] = 0;
	idd['E'] = 3;
	idd['W'] = 2;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			char c; cin >> c;
			f[0][i][j] = (c == '.');
			a[i][j] = f[0][i][j]; 
		}
	}
	string s; cin >> s;
	for(int t = 1; t <= k; t++) {
		char c = s[t - 1];
		int id = t & 1;
		if(c == '?') {
			for(int i = 1; i <= n; i++) {
				for(int j = 1; j <= m; j++) {
					if(a[i][j] == 0) continue;
					f[id][i][j] = 0;
					for(int z = 0; z < 4; z++) {
						int nx = i + d[z].fi, ny = j + d[z].se;
						if(nx < 1 or ny < 1 or nx > n or ny > m) continue;
						f[id][i][j] = f[id ^ 1][nx][ny];
						if(f[id][i][j]) break;
					}
				}
			}
		} else if(c == 'N') {
			for(int i = 1; i < n; i++) {
				f[id][i] = f[id ^ 1][i + 1] & a[i];
			}
			f[id][n].reset();
		} else if(c == 'S') {
			f[id][0].reset();
			for(int i = 2; i <= n; i++) {
				f[id][i] = f[id ^ 1][i - 1] & a[i];
			}
		} else if(c == 'E') {
			for(int i = 1; i <= n; i++) f[id][i] = (f[id ^ 1][i] >> 1) & a[i]; 
		} else {
			for(int i = 1; i <= n; i++) f[id][i] = (f[id ^ 1][i] << 1) & a[i];
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			ans += f[k & 1][i][j];
		}
	}
	cout << ans << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

nautilus.cpp: In function 'int main()':
nautilus.cpp:25:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:26:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...