This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int SZ = 5002;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
int r, c, m;
cin >> r >> c >> m;
vector<bitset<SZ>> g(r + 2);
for(int i = 1; i <= r; i++){
string t;
cin >> t;
for(int j = 0; j < c; j++){
if(t[j] == '.') g[i][c - j] = 1;
}
//cerr << t << "\n";
//cerr << g[i] << "\n";
}
//for(int i = 0; i <= r + 1; i++) cerr << g[i] << "\n";
string s;
cin >> s;
vector<bitset<SZ>> dp = g;
for(char d : s){
vector<bitset<SZ>> dp2(r + 2);
if(d == 'S' || d == '?'){
for(int i = 1; i <= r; i++) dp2[i] |= dp[i - 1];
}
if(d == 'N' || d == '?'){
for(int i = 1; i <= r; i++) dp2[i] |= dp[i + 1];
}
if(d == 'E' || d == '?'){
for(int i = 1; i <= r; i++) dp2[i] |= dp[i] >> 1;
}
if(d == 'W' || d == '?'){
for(int i = 1; i <= r; i++) dp2[i] |= dp[i] << 1;
}
//cerr << "test " << d << "\n";
//for(int i = 0; i <= r + 1; i++) cerr << dp2[i] << "\n";
for(int i = 1; i <= r; i++) dp2[i] &= g[i];
dp.swap(dp2);
//cerr << "test " << d << "\n";
//for(int i = 0; i <= r + 1; i++) cerr << dp[i] << "\n";
}
int ans = 0;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
if(dp[i][j]) ans++;
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |