#include <bits/stdc++.h>
#define MAX 505
typedef std::bitset<MAX> bits;
std::deque<bits> deq;
int R,C,M;
std::string comandos;
bits mapa[MAX];
bits em={};
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cin>>R>>C>>M;
for(int i=0;i!=R;++i){
bits x={};
std::string s;
std::cin >> s;
for(int j=0;j!=C;++j){
if(s[j]!='#')x[j]=1;
}
mapa[i]=x;
}
for(int i=0;i!=R;++i){
bits x=mapa[i];
deq.push_back(x);
}
std::cin>>comandos;
for(int i=0;i!=M;++i){
char ch = comandos[i];
switch(ch){
///Right
case 'W':{
for(int i=0;i!=R;++i){
deq[i]=(deq[i]>>1)&mapa[i];
}
}break;
///Left
case 'E':{
for(int i=0;i!=R;++i){
deq[i]=(deq[i]<<1)&mapa[i];
}
}break;
///North:
case 'N':{
for(int i=0;i!=R-1;++i){
deq[i]=(deq[i+1])&mapa[i];
}
deq[R-1]=em;
}break;
///South
case 'S':{
for(int i=R-1;i!=0;--i){
deq[i]=(deq[i-1])&mapa[i];
}
deq[0]=em;
}break;
///Mystery
case '?':{
std::deque<bits> nov;
for(int i=0;i!=R;++i){
bits x={};
nov.push_back(x);
}
for(int i=0;i!=R;++i){
nov[i]|=(deq[i]>>1)&mapa[i];
}
for(int i=0;i!=R;++i){
nov[i]|=(deq[i]<<1)&mapa[i];
}
for(int i=0;i!=R-1;++i){
nov[i]|=(deq[i+1])&mapa[i];
}
for(int i=1;i!=R;++i){
nov[i]|=(deq[i-1])&mapa[i];
}
deq=nov;
}break;
}
}
int count=0;
for(auto&x:deq)count+=x.count();
std::cout<<count<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
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 |
468 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 |
468 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 |
600 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 |
348 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 |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 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 |
468 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 |
600 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 |
348 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 |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
74 ms |
852 KB |
Output is correct |
23 |
Correct |
79 ms |
604 KB |
Output is correct |
24 |
Correct |
70 ms |
724 KB |
Output is correct |
25 |
Correct |
70 ms |
808 KB |
Output is correct |
26 |
Correct |
72 ms |
604 KB |
Output is correct |
27 |
Correct |
119 ms |
804 KB |
Output is correct |
28 |
Correct |
121 ms |
604 KB |
Output is correct |
29 |
Correct |
121 ms |
604 KB |
Output is correct |
30 |
Correct |
124 ms |
604 KB |
Output is correct |
31 |
Correct |
120 ms |
604 KB |
Output is correct |
32 |
Correct |
157 ms |
828 KB |
Output is correct |
33 |
Correct |
156 ms |
604 KB |
Output is correct |
34 |
Correct |
165 ms |
808 KB |
Output is correct |
35 |
Correct |
158 ms |
812 KB |
Output is correct |
36 |
Correct |
164 ms |
808 KB |
Output is correct |