Submission #328922

# Submission time Handle Problem Language Result Execution time Memory
328922 2020-11-18T13:05:56 Z egas Nautilus (BOI19_nautilus) C++14
100 / 100
206 ms 1260 KB
#include <bits/stdc++.h>

using namespace std;

template<size_t TT >

void set_bit(bitset<TT> &x,int idx,int val) {

    x[x.size()-idx-1]=val;

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int r;

    cin >> r;

    int c;

    cin >> c;

    int m;

    cin >> m;

    vector<string> grid;

    for(int i = 0 ; i < r ; i++) {

        string temp;

        cin >> temp;

        grid.push_back(temp);

    }

    string path;

    cin >> path;

    vector<bitset<501>> isValid(501);

    for(int i = 0 ; i < r ; i++) {

        for(int j = 0 ; j < c ; j++) {

            if(grid[i][j]=='.') {

                set_bit(isValid[i],j,1);

            }

        }

    }

    vector<vector<bitset<501>>> canVisit(2,vector<bitset<501>>(501));

    int res=0;

    for(int i = 0 ; i < r ; i++) {

        for(int j = 0 ; j < c ; j++) {

            if(grid[i][j]=='.') {

                set_bit(canVisit[0][i],j,1);

            }

        }

    }

    for(int k=0; k<path.length(); k++) {

        if(path[k]=='S') {

            for(int i = 0 ; i < r ; i++) {

                if(i-1>=0)

                    canVisit[1][i]=(canVisit[0][(i-1)])&isValid[i];

            }

        } else if(path[k]=='N') {

            for(int i = 0 ; i < r ; i++) {

                if(i+1<r)

                    canVisit[1][i]=(canVisit[0][(i+1)])&isValid[i];

            }

        } else if(path[k]=='E') {

            for(int i = 0 ; i < r ; i++) {

                canVisit[1][i]=(canVisit[0][i]>>1)&isValid[i];

            }

        } else if(path[k]=='W') {

            for(int i = 0 ; i < r ; i++) {

                canVisit[1][i]=(canVisit[0][i]<<1)&isValid[i];

            }

        } else {

            for(int i = 0 ; i < r ; i++) {

                canVisit[1][i]=(canVisit[0][i]<<1)&isValid[i];

                canVisit[1][i]|=(canVisit[0][i]>>1)&isValid[i];

                if(i-1>=0)

                    canVisit[1][i]|=(canVisit[0][(i-1)])&isValid[i];

                if(i+1<r)

                    canVisit[1][i]|=(canVisit[0][(i+1)])&isValid[i];

            }

        }

        for(int i = 0 ; i < r ; i++) {

            canVisit[0][i] = canVisit[1][i];

            canVisit[1][i].reset();

        }

    }

    for(int i = 0 ; i < r ; i++) {

        for(int j = 0 ; j < c ; j++) {

            res+=canVisit[0][i][501-j-1];

        }

    }

    cout << res << '\n';

    return 0;

}

Compilation message

nautilus.cpp: In function 'int32_t main()':
nautilus.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int k=0; k<path.length(); k++) {
      |                  ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 524 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 524 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 524 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 100 ms 1068 KB Output is correct
23 Correct 99 ms 1004 KB Output is correct
24 Correct 100 ms 1004 KB Output is correct
25 Correct 95 ms 1004 KB Output is correct
26 Correct 101 ms 1004 KB Output is correct
27 Correct 145 ms 1068 KB Output is correct
28 Correct 162 ms 1260 KB Output is correct
29 Correct 161 ms 1004 KB Output is correct
30 Correct 157 ms 1132 KB Output is correct
31 Correct 155 ms 1068 KB Output is correct
32 Correct 206 ms 1004 KB Output is correct
33 Correct 196 ms 1004 KB Output is correct
34 Correct 181 ms 1068 KB Output is correct
35 Correct 179 ms 1132 KB Output is correct
36 Correct 179 ms 1132 KB Output is correct