Submission #159572

#TimeUsernameProblemLanguageResultExecution timeMemory
159572DrSwadNautilus (BOI19_nautilus)C++17
66 / 100
1058 ms1272 KiB
#include<bits/stdc++.h>

using namespace std;

const int N = 505, M = 5005;

enum dir {
	UP,
	RIGHT,
	DOWN,
	LEFT,
	ALL
};

int r, c, m;
char cell[N][N];
bool vis[2][N][N];
dir moves[M];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	scanf("%d %d %d", &r, &c, &m);

	for (int i = 1; i <= r; i++) {
		scanf("%s", cell[i] + 1);
	}

	char s[M];
	scanf("%s", s + 1);
	for (int i = 1; i <= m; i++) {
		switch (s[i]) {
			case 'N':
				moves[i] = UP;
				break;
			case 'E':
				moves[i] = RIGHT;
				break;
			case 'S':
				moves[i] = DOWN;
				break;
			case 'W':
				moves[i] = LEFT;
				break;
			default:
				moves[i] = ALL;
				break;
		}
	}

	for (int _r = 1; _r <= r; _r++) {
		for (int _c = 1; _c <= c; _c++) {
			vis[0][_r][_c] = cell[_r][_c] == '.';
		}
	}

	for (int i = 1; i <= m; i++) {
		fill(&vis[i % 2][0][0], &vis[i % 2 + 1][0][0], false);

		for (int _r = 1; _r <= r; _r++) {
			for (int _c = 1; _c <= c; _c++) {
				if (!vis[(i - 1) % 2][_r][_c]) continue;

				for (int d = 0; d < 4; d++) {
					if (d != moves[i] && moves[i] != ALL) continue;
					int _x = _r + dx[d];
					int _y = _c + dy[d];

					if (_x < 1 || r < _x || _y < 1 || c < _y || cell[_x][_y] != '.') continue;

					vis[i % 2][_x][_y] = true;
				}
			}
		}
	}

	cout << accumulate(&vis[m % 2][0][0], &vis[m % 2 + 1][0][0], 0) << endl;

	return 0;
}

Compilation message (stderr)

nautilus.cpp: In function 'int main()':
nautilus.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &r, &c, &m);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", cell[i] + 1);
   ~~~~~^~~~~~~~~~~~~~~~~~~
nautilus.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s + 1);
  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...