Submission #857186

#TimeUsernameProblemLanguageResultExecution timeMemory
857186Trisanu_DasNautilus (BOI19_nautilus)C++17
100 / 100
163 ms1372 KiB
#include <bits/stdc++.h>
using namespace std;

int r,c,m;
vector<string> a;

bool valid_pos(int i, int j){
    return !(i < 0 || j < 0 || i >= r || j >= c || a[i][j] == '#');
}

int main(){
    cin >> r >> c >> m;
    a.resize(r);
    for(int i = 0; i < r; ++i) cin >> a[i];
    string msg; cin >> msg;
    bitset<1000> dp[r],temp[r],aa[r];
    for(int i = 0; i < r; ++i){
        for(int j = 0; j < c; ++j){
            aa[i][j] = a[i][c-1-j] == '.';
            dp[i][j] = a[i][c-1-j] == '.';
        }
    }
    for(char w : msg){
        for(int i = 0; i < r; ++i){
            if(w == 'W') dp[i] = (dp[i]<<1)&aa[i];
            if(w == 'E') dp[i] = (dp[i]>>1)&aa[i];
            if(w == 'N')
                if(i+1 < r) dp[i] = dp[i+1]&aa[i];
                else dp[i].reset();
            if(w == '?'){
                temp[i] = (dp[i]<<1)|(dp[i]>>1);
                if(i) temp[i] |= dp[i-1];
                if(i+1 < r) temp[i] |= dp[i+1];
                temp[i] &= aa[i];
            }
        }
        for(int i = r-1; i >= 0; --i)
            if(w == 'S')
                if(i) dp[i] = dp[i-1]&aa[i];
                else dp[i].reset();
        for(int i = 0; i < r; ++i) if(w == '?') dp[i] = temp[i];
    }
    int ans = 0;
    for(int i = 0; i < r; ++i) ans += dp[i].count();
    cout << ans << '\n';
}

Compilation message (stderr)

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