#include<bits/stdc++.h>
using namespace std;
int main() {
int x,y , m;
cin>>x>>y>>m;
char map[x][y];
bool dp[x][y][4]={};
for(int i=0; i<x; i++) {
for(int j=0; j<y; j++) {
cin>>map[i][j];
}
}
string rotations;
cin>>rotations;
for(int i=0; i<x; i++) {
for(int j=0; j<y; j++) {
if(map[i][j]=='#') {
continue;
}
if(i>0 and map[i-1][j]!='#') {
dp[i][j][0]=true;
}
if(j<y-1 and map[i][j+1]!='#') {
dp[i][j][1]=true;
}
if(i<x-1 and map[i+1][j]!='#') {
dp[i][j][2]=true;
}
if(j>0 and map[i][j-1]!='#') {
dp[i][j][3]=true;
}
}
}
for(int i=0; i<x; i++) {
for(int j=0; j<y; j++) {
for(int k=0; k<4; k++) {
cout<<dp[i][j][k]<<" ";
}
cout<<'|';
}
cout<<'|'<<endl;
}
int ans=0;
for(int i=0; i<x; i++) {
for(int j=0; j<y; j++) {
if(map[i][j]=='#') {
continue;
}
bool canRotate=true;
int dx=0, dy=0;
for( char r : rotations) {
if(r=='N' and dp[i+dx][j+dy][0]) {
dx--;
continue;
}
if(r=='E' and dp[i+dx][j+dy][1]) {
dy++;
continue;
}
if(r=='S' and dp[i+dx][j+dy][2]) {
dx++;
continue;
}
if(r=='W' and dp[i+dx][j+dy][3]) {
dy--;
continue;
}
if(r=='?') {
if(dp[i+dx][j+dy][0]) {
dx--;
}
else if(dp[i+dx][j+dy][1]) {
dy++;
}
else if(dp[i+dx][j+dy][2]) {
dx++;
}
else if(dp[i+dx][j+dy][3]) {
dy--;
}
continue;
}
canRotate=false;
break;
}
if(canRotate) {
ans++;
}
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |