#include <bits/stdc++.h>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
// We can do this using bitsets but we need some way to keep track of the #s
/* Case 1: N, S, E, W we shift the bitset (and) it with current mask
* Case 2: ? or all 4 shifted masks and then (and) it with current mask
*/
const int N = 9;
using B = bitset<N>;
int r,c;
vector<B> ocean, msk;
vector<B> north(){
vector<B> temp(r);
for(int i = 0;i<r - 1;i++){
temp[i] = ocean[i + 1];
}
return temp;
}
vector<B> south(){
vector<B> temp(r);
for(int i = 0;i<r - 1;i++){
temp[i + 1] = ocean[i];
}
return temp;
}
vector<B> west(){
vector<B> temp = ocean;
for(int i = 0;i<r;i++){
temp[i] = temp[i] << 1;
}
return temp;
}
vector<B> east(){
vector<B> temp = ocean;
for(int i = 0;i<r;i++){
temp[i] = temp[i] >> 1;
}
return temp;
}
void ord(vector<B> &o, vector<B> so){
for(int i = 0;i<r;i++){
o[i] |= so[i];
}
}
signed main(){
iostream::sync_with_stdio(false);cin.tie(nullptr);
int m;cin >> r >> c >> m;
ocean.resize(r);
for(int i = 0;i<r;i++){
string t;cin >> t;
for(int j = 0;j<c;j++){
if(t[j] == '.'){
ocean[i][j] = 1;
}
}
}
msk = ocean;
string s;cin >> s;
for(int i = 0;i<s.size();i++){
vector<B> so;
if(s[i] == '?'){
so = north();
ord(so, south());
ord(so, west());
ord(so, east());
}
else{
if(s[i] == 'N'){
so = north();
}
else if(s[i] == 'S'){
so = south();
}
else if(s[i] == 'E'){
so = west();
}
else{
so = east();
}
}
ocean = so;
for(int j = 0;j<r;j++)
ocean[j] &= msk[j];
}
int cc = 0;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
if(ocean[i][j] == 1)
cc++;
}
}
cout << cc << "\n";
}
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0;i<s.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |