Submission #1156988

#TimeUsernameProblemLanguageResultExecution timeMemory
1156988htphong0909Nautilus (BOI19_nautilus)C++20
66 / 100
1097 ms13828 KiB
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

bitset<1250250001> vis;
int n, m, h;

inline int ch(const int& a, const  int& b, const  int& c) {
    return (a - 1) * m + b + c * n * m;
}

char arr[501][501];

inline bool in(const int& x, const int& y) {
    return x > 0 && x <= n && y > 0 && y <= m && arr[x][y] == '.';
}

pair<int, int> di[101];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    queue<array<short, 3>> q;
    cin >> n >> m >> h;
    di['N' - 'A'] = make_pair(-1, 0);
    di['S' - 'A'] = make_pair(1, 0);
    di['W' - 'A'] = make_pair(0, -1);
    di['E' - 'A'] = make_pair(0, 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> arr[i][j];
            if (arr[i][j] == '.') {
                q.push({i, j, 0});
                vis[ch(i, j, 0)] = true;
            }
        }
    }
    string s;
    cin >> s;
    s = '.' + s;
    int ans = 0;
    while (!q.empty()) {
        const int ux = q.front()[0];
        const int uy = q.front()[1];
        const int uk = q.front()[2];
        q.pop();
        if (uk == h) {
            ans++;
            continue;
        }
        if (const int vk = uk + 1; s[vk] == '?') {
            for (int i = 0; i < 4; i++) {
                int vx = ux + dx[i];
                int vy = uy + dy[i];
                if (!in(vx, vy) || vis[ch(vx, vy, vk)]) continue;
                q.push({vx, vy, vk});
                vis[ch(vx, vy, vk)] = true;
            }
        }
        else {
            int vx = ux + di[s[vk] - 'A'].first;
            int vy = uy + di[s[vk] - 'A'].second;
            if (!in(vx, vy) || vis[ch(vx, vy, vk)]) continue;
            q.push({vx, vy, vk});
            vis[ch(vx, vy, vk)] = true;
        }
    }
    cout << ans;
    return 0;
}

Compilation message (stderr)

nautilus.cpp: In function 'int32_t main()':
nautilus.cpp:38:25: warning: narrowing conversion of 'i' from 'int' to 'short int' [-Wnarrowing]
   38 |                 q.push({i, j, 0});
      |                         ^
nautilus.cpp:38:28: warning: narrowing conversion of 'j' from 'int' to 'short int' [-Wnarrowing]
   38 |                 q.push({i, j, 0});
      |                            ^
nautilus.cpp:61:25: warning: narrowing conversion of 'vx' from 'int' to 'short int' [-Wnarrowing]
   61 |                 q.push({vx, vy, vk});
      |                         ^~
nautilus.cpp:61:29: warning: narrowing conversion of 'vy' from 'int' to 'short int' [-Wnarrowing]
   61 |                 q.push({vx, vy, vk});
      |                             ^~
nautilus.cpp:61:33: warning: narrowing conversion of '(int)vk' from 'int' to 'short int' [-Wnarrowing]
   61 |                 q.push({vx, vy, vk});
      |                                 ^~
nautilus.cpp:69:21: warning: narrowing conversion of 'vx' from 'int' to 'short int' [-Wnarrowing]
   69 |             q.push({vx, vy, vk});
      |                     ^~
nautilus.cpp:69:25: warning: narrowing conversion of 'vy' from 'int' to 'short int' [-Wnarrowing]
   69 |             q.push({vx, vy, vk});
      |                         ^~
nautilus.cpp:69:29: warning: narrowing conversion of '(int)vk' from 'int' to 'short int' [-Wnarrowing]
   69 |             q.push({vx, vy, vk});
      |                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...