Submission #123012

#TimeUsernameProblemLanguageResultExecution timeMemory
123012model_codeNautilus (BOI19_nautilus)C++17
100 / 100
273 ms1088 KiB
#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)

nautilus.cpp: In function 'int main()':
nautilus.cpp:30:15: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
             if(w == 'N')
               ^
nautilus.cpp:45:15: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
             if(w == 'S')
               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...