이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |