Submission #159633

# Submission time Handle Problem Language Result Execution time Memory
159633 2019-10-23T16:09:00 Z DrSwad Nautilus (BOI19_nautilus) C++11
66 / 100
1000 ms 95248 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")

#ifdef LOCAL
#include "debug.h"
#endif

typedef long long ll;
typedef unsigned int uint;

typedef pair<int, int> pii;
#define x first
#define y second

#define size(a) (int)a.size()

const int N = 505, M = 5005;

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

int r, c, m;
char cell[N][N];
bool vis[M][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++) {
		for (int _r = 1; _r <= r; _r++) {
			for (int _c = 1; _c <= c; _c++) {
				if (!vis[i - 1][_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][_x][_y] = true;
				}
			}
		}
	}

	cout << accumulate(&vis[m][0][0], &vis[m][0][0] + sizeof(vis[m]), 0) << endl;

	return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:45: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:48: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:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s + 1);
  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 5496 KB Output is correct
2 Correct 8 ms 4984 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 6 ms 1400 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 5496 KB Output is correct
2 Correct 8 ms 4984 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 6 ms 1400 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 16 ms 5752 KB Output is correct
8 Correct 11 ms 5752 KB Output is correct
9 Correct 8 ms 4600 KB Output is correct
10 Correct 6 ms 2140 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 22 ms 5752 KB Output is correct
13 Correct 23 ms 5724 KB Output is correct
14 Correct 21 ms 5800 KB Output is correct
15 Correct 8 ms 4984 KB Output is correct
16 Correct 5 ms 1272 KB Output is correct
17 Correct 27 ms 5752 KB Output is correct
18 Correct 29 ms 5880 KB Output is correct
19 Correct 20 ms 5752 KB Output is correct
20 Correct 11 ms 5752 KB Output is correct
21 Correct 5 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 5496 KB Output is correct
2 Correct 8 ms 4984 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 6 ms 1400 KB Output is correct
5 Correct 5 ms 1272 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 16 ms 5752 KB Output is correct
8 Correct 11 ms 5752 KB Output is correct
9 Correct 8 ms 4600 KB Output is correct
10 Correct 6 ms 2140 KB Output is correct
11 Correct 5 ms 1144 KB Output is correct
12 Correct 22 ms 5752 KB Output is correct
13 Correct 23 ms 5724 KB Output is correct
14 Correct 21 ms 5800 KB Output is correct
15 Correct 8 ms 4984 KB Output is correct
16 Correct 5 ms 1272 KB Output is correct
17 Correct 27 ms 5752 KB Output is correct
18 Correct 29 ms 5880 KB Output is correct
19 Correct 20 ms 5752 KB Output is correct
20 Correct 11 ms 5752 KB Output is correct
21 Correct 5 ms 1272 KB Output is correct
22 Execution timed out 1081 ms 95248 KB Time limit exceeded
23 Halted 0 ms 0 KB -