답안 #891608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891608 2023-12-23T10:29:50 Z vjudge1 Nautilus (BOI19_nautilus) C++17
100 / 100
199 ms 856 KB
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define file(s) if(fopen(s".in","r")) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
#define all(x) (x).begin(), (x).end()
#define len(x) (int)x.size()
#define tm (tl + tr >> 1)
#define ls v << 1, tl, tm
#define rs v << 1 | 1, tm + 1, tr
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define elif else if
#define F first
#define S second
#define int long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;

const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const int P = 911;
const ll INF = 1e18;

int rnd() {
	int x = rand() << 15;
	return x ^ rand();
}

void GazizMadi() {
	int n, m, k;
	cin >> n >> m >> k;
	bitset <500> ans[n], ok[n], we[n], ea[n], no[n], so[n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			bool now = (c == '.');
			ans[i][j] = now;
			ok[i][j] = now;
		}
	}
	string s;
	cin >> s;
	for (int t = 0; t < k; t++) {
		if (s[t] == 'N') {
			for (int i = 0; i < n - 1; i++) {
				ans[i] = ans[i + 1] & ok[i];
			}
			for (int j = 0; j < m; j++) {
				ans[n - 1][j] = 0;
			}
		}
		if (s[t] == 'S') {
			for (int i = n - 1; i > 0; i--) {
				ans[i] = ans[i - 1] & ok[i];
			}
			for (int j = 0; j < m; j++) {
				ans[0][j] = 0;
			}
		}
		if (s[t] == 'W') {
			for (int i = 0; i < n; i++) {
				ans[i] >>= 1;
				ans[i] &= ok[i];
			}
		}
		if (s[t] == 'E') {
			for (int i = 0; i < n; i++) {
				ans[i] <<= 1;
				ans[i] &= ok[i];
			}
		}
		if (s[t] == '?') {
			for (int i = 0; i < n; i++) {
				no[i] = ans[i];
				so[i] = ans[i];
				we[i] = ans[i];
				ea[i] = ans[i];
			}
			for (int i = 0; i < n - 1; i++) {
				no[i] = no[i + 1] & ok[i];
			}
			for (int i = n - 1; i > 0; i--) {
				so[i] = so[i - 1] & ok[i];
			}
			for (int j = 0; j < m; j++) {
				no[n - 1][j] = 0;
				so[0][j] = 0;
			}
			for (int i = 0; i < n; i++) {
				we[i] >>= 1;
				we[i] &= ok[i];
				ea[i] <<= 1;
				ea[i] &= ok[i];
			}
			for (int i = 0; i < n; i++) {
				ans[i] = (no[i] | so[i] | we[i] | ea[i]);
				ans[i] &= ok[i];
			}
		}
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			res += ans[i][j];
		}
	}
	cout << res;
}

const bool Cases = 0;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	srand(time(0));
	int TT = 1;
	if (Cases) cin >> TT;
	for (int i = 1; i <= TT; i++) {
		//cout << "Case " << i << ": ";
		GazizMadi();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 424 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 424 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 81 ms 604 KB Output is correct
23 Correct 84 ms 600 KB Output is correct
24 Correct 82 ms 600 KB Output is correct
25 Correct 79 ms 856 KB Output is correct
26 Correct 77 ms 600 KB Output is correct
27 Correct 145 ms 624 KB Output is correct
28 Correct 148 ms 624 KB Output is correct
29 Correct 147 ms 604 KB Output is correct
30 Correct 148 ms 604 KB Output is correct
31 Correct 147 ms 640 KB Output is correct
32 Correct 197 ms 604 KB Output is correct
33 Correct 197 ms 628 KB Output is correct
34 Correct 199 ms 636 KB Output is correct
35 Correct 199 ms 600 KB Output is correct
36 Correct 197 ms 628 KB Output is correct