Submission #221382

# Submission time Handle Problem Language Result Execution time Memory
221382 2020-04-10T00:55:38 Z Leonardo_Paes Nautilus (BOI19_nautilus) C++17
100 / 100
59 ms 512 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")

const int maxn = 510;

int r, c, m, ans = 0;

bitset<maxn> dp[maxn], mat[maxn], tfg[maxn];

string s;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    cin >> r >> c >> m;

    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            char a;
            cin >> a;
            if(a == '.') mat[i][c-j-1] = dp[i][c-j-1] = 1;
        }
    }

    cin >> s;

    for(int j=0; j<s.size(); j++){
        if(s[j] == 'N'){
            for(int i=0; i<r; i++){
                if(i+1 < r) dp[i] = (dp[i+1] & mat[i]);
                else dp[i].reset();
            }
        }
        if(s[j] == 'S'){
            for(int i=r-1; i>=0; i--){
                if(i) dp[i] = (dp[i-1] & mat[i]);
                else dp[i].reset();
            }
        }
        if(s[j] == 'E'){
            for(int i=0; i<r; i++){
                dp[i] = ((dp[i] >> 1) & mat[i]);
            }
        }
        if(s[j] == 'W'){
            for(int i=0; i<r; i++){
                dp[i] = ((dp[i] << 1) & mat[i]);
            }
        }
        if(s[j] == '?'){
            for(int i=0; i<r; i++){
                tfg[i] = (dp[i] << 1)|(dp[i] >> 1);
                if(i) tfg[i] |= dp[i-1];
                if(i+1 < r) tfg[i] |= dp[i+1];
                tfg[i] &= mat[i];
            }
            for(int i=0; i<r; i++){
                dp[i] = tfg[i];
            }
        }
    }

    for(int i=0; i<r; i++) ans += dp[i].count();

    cout << ans << endl;

    return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:30:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0; j<s.size(); j++){
                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 31 ms 512 KB Output is correct
23 Correct 32 ms 384 KB Output is correct
24 Correct 31 ms 384 KB Output is correct
25 Correct 32 ms 508 KB Output is correct
26 Correct 30 ms 384 KB Output is correct
27 Correct 45 ms 384 KB Output is correct
28 Correct 47 ms 384 KB Output is correct
29 Correct 47 ms 384 KB Output is correct
30 Correct 45 ms 384 KB Output is correct
31 Correct 45 ms 384 KB Output is correct
32 Correct 57 ms 384 KB Output is correct
33 Correct 59 ms 512 KB Output is correct
34 Correct 59 ms 384 KB Output is correct
35 Correct 58 ms 384 KB Output is correct
36 Correct 58 ms 384 KB Output is correct