# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
123012 | model_code | Nautilus (BOI19_nautilus) | C++17 | 273 ms | 1088 KiB |
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 <iostream>
#include <vector>
#include <bitset>
using namespace std;
int r,c,m;
vector<string> grid;
bool valid_pos(int i, int j){
return !(i < 0 || j < 0 || i >= r || j >= c || grid[i][j] == '#');
}
int main(){
cin >> r >> c >> m;
grid.resize(r);
for(int i = 0; i < r; ++i)
cin >> grid[i];
string msg;
cin >> msg;
bitset<1000> reach[r],tmp[r],sea[r];
for(int i = 0; i < r; ++i){
for(int j = 0; j < c; ++j){
sea[i][j] = grid[i][c-1-j] == '.';
reach[i][j] = grid[i][c-1-j] == '.';
}
}
for(char w : msg){
for(int i = 0; i < r; ++i){
if(w == 'W')
reach[i] = (reach[i]<<1)&sea[i];
if(w == 'E')
reach[i] = (reach[i]>>1)&sea[i];
if(w == 'N')
if(i+1 < r)
reach[i] = reach[i+1]&sea[i];
else
reach[i].reset();
if(w == '?'){
tmp[i] = (reach[i]<<1)|(reach[i]>>1);
if(i)
tmp[i] |= reach[i-1];
if(i+1 < r)
tmp[i] |= reach[i+1];
tmp[i] &= sea[i];
}
}
for(int i = r-1; i >= 0; --i)
if(w == 'S')
if(i)
reach[i] = reach[i-1]&sea[i];
else
reach[i].reset();
for(int i = 0; i < r; ++i)
if(w == '?')
reach[i] = tmp[i];
}
int ans = 0;
for(int i = 0; i < r; ++i)
ans += reach[i].count();
cout << ans << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |