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>
#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";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |