Submission #533007

# Submission time Handle Problem Language Result Execution time Memory
533007 2022-03-04T10:49:34 Z akhan42 Nautilus (BOI19_nautilus) C++17
100 / 100
355 ms 1104 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define lc v << 1
#define rc (v << 1) + 1
#define at(m, k) (m.find(k) == m.end() ? 0 : m[k])

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }


const int MX = 502;
bitset<MX * MX> bs;
bitset<MX * MX> msk;
int r, c, m;


int cl(int i, int j) {
	return i * (c + 2) + j;
}


void solve() {
	cin >> r >> c >> m;

	forn(i, r) {
		forn(j, c) {
			char ch;
			cin >> ch;
			if(ch == '#')
				bs[cl(i + 1, j + 1)] = msk[cl(i + 1, j + 1)] = 1;
		}
	}

	forn(i, r + 2) {
		forn(j, c + 2) {
			bs[cl(0, j)] = bs[cl(r + 1, j)] = msk[cl(0, j)] = msk[cl(r + 1, j)] = 1;
		}
		bs[cl(i, 0)] = bs[cl(i, c + 1)] = msk[cl(i, 0)] = msk[cl(i, c + 1)] = 1;
	}

	string s;
	cin >> s;
	for(int t = m - 1; t >= 0; t--) {
		char ch = s[t];
		if(ch == 'E') {
			bs = (bs >> 1) | msk;
		}
		if(ch == 'W') {
			bs = (bs << 1) | msk;
		}
		if(ch == 'N') {
			bs = (bs << (c + 2)) | msk;
		}
		if(ch == 'S') {
			bs = (bs >> (c + 2)) | msk;
		}
		if(ch == '?') {
			bs = (bs << 1) & (bs >> 1) & (bs >> (c + 2)) & (bs << (c + 2));
			bs |= msk;
		}
	}

	bs.flip();
	forn(i, (r + 2) * (c + 2))
		msk.flip(i);
	bs &= msk;

	for(char ch: s) {
		if(ch == 'E')
			bs = (bs << 1) & msk;
		if(ch == 'W')
			bs = (bs >> 1) & msk;
		if(ch == 'N')
			bs = (bs >> (c + 2)) & msk;
		if(ch == 'S')
			bs = (bs << (c + 2)) & msk;
		if(ch == '?') {
			bs = (bs << 1) | (bs >> 1) | (bs >> (c + 2)) | (bs << (c + 2));
			bs &= msk;
		}
	}

	cout << bs.count() << '\n';
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

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

	int t = 1;
//	cin >> t;
	while(t--) {
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 728 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 728 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 716 KB Output is correct
7 Correct 4 ms 720 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 7 ms 728 KB Output is correct
10 Correct 5 ms 720 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 6 ms 716 KB Output is correct
13 Correct 6 ms 724 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 6 ms 752 KB Output is correct
16 Correct 7 ms 720 KB Output is correct
17 Correct 8 ms 716 KB Output is correct
18 Correct 8 ms 716 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 8 ms 724 KB Output is correct
21 Correct 8 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 728 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 3 ms 716 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 716 KB Output is correct
7 Correct 4 ms 720 KB Output is correct
8 Correct 4 ms 716 KB Output is correct
9 Correct 7 ms 728 KB Output is correct
10 Correct 5 ms 720 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 6 ms 716 KB Output is correct
13 Correct 6 ms 724 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 6 ms 752 KB Output is correct
16 Correct 7 ms 720 KB Output is correct
17 Correct 8 ms 716 KB Output is correct
18 Correct 8 ms 716 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 8 ms 724 KB Output is correct
21 Correct 8 ms 716 KB Output is correct
22 Correct 185 ms 1012 KB Output is correct
23 Correct 184 ms 1012 KB Output is correct
24 Correct 189 ms 1024 KB Output is correct
25 Correct 174 ms 1016 KB Output is correct
26 Correct 164 ms 960 KB Output is correct
27 Correct 270 ms 1012 KB Output is correct
28 Correct 269 ms 1016 KB Output is correct
29 Correct 266 ms 972 KB Output is correct
30 Correct 298 ms 1012 KB Output is correct
31 Correct 264 ms 972 KB Output is correct
32 Correct 355 ms 1104 KB Output is correct
33 Correct 353 ms 1020 KB Output is correct
34 Correct 339 ms 1016 KB Output is correct
35 Correct 349 ms 1020 KB Output is correct
36 Correct 337 ms 972 KB Output is correct