Submission #673841

# Submission time Handle Problem Language Result Execution time Memory
673841 2022-12-22T09:17:15 Z Duy_e Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 128680 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define file "test"
#define rep(i, begin, end) for (ll i = (begin); i <= (end); i ++)
#define rrep(i, begin, end) for (ll i = (begin); i >= (end); i --)
using namespace std;
const long long INF = 1e18;
const long long N = 500 + 5;

char a[N][N];
string s;
int R, C, M;

struct node {
    int x, y, i;
    node(int _x, int _y, int _i) {
        x = _x; y = _y; i = _i;
    }

    bool legal() {
        return x >= 1 && x <= R && y >= 1 && y <= C && i <= M && a[x][y] == '.';
    }
};


namespace sub12 {
    
    int dr[] = {-1, 1, 0, 0}, dc[] = {0, 0, -1, 1};
    int dir[300];

    bool dp[N][N][N];

    void init() {
        dir['N'] = 0;
        dir['S'] = 1;
        dir['E'] = 3;
        dir['W'] = 2; 
        dir['?'] = -1;
    }

    node nxt(node x, char ch) {
        int d = dir[ch];
        x.x += dr[d];
        x.y += dc[d];
        x.i ++;
        return x;
    }

    void solve() {
        init();
        queue <node> q;
        
        string direction = "WENS";

        rep(i, 1, R) rep(j, 1, C) if (a[i][j] == '.')
            q.push(node(i, j, 0)), dp[i][j][0] = 1;

        while (q.size()) {
            node u = q.front(); q.pop();
            if (u.i == M) continue;

            char ch = s[u.i];
            for (char x: direction) if (ch == '?' || x == ch) {
                node v = nxt(u, x);
                if (v.legal()) {
                    if (!dp[v.x][v.y][v.i]) {
                        dp[v.x][v.y][v.i] = true;
                        q.push(v);
                    }
                }
            }
        }

        int ans = 0;
        rep(i, 1, R) rep(j, 1, C) if (dp[i][j][M]) ans ++;
    
        cout << ans << '\n';
    }
};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //     freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    // #endif
    
    cin >> R >> C >> M;

    rep(i, 1, R) rep(j, 1, C) 
        cin >> a[i][j];

    cin >> s;
    sub12 :: solve();
    return 0;
}  

Compilation message

nautilus.cpp: In function 'node sub12::nxt(node, char)':
nautilus.cpp:45:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |         int d = dir[ch];
      |                     ^~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5852 KB Output is correct
2 Correct 4 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 2 ms 4692 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5852 KB Output is correct
2 Correct 4 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 2 ms 4692 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 27 ms 5856 KB Output is correct
8 Correct 9 ms 5596 KB Output is correct
9 Correct 4 ms 5460 KB Output is correct
10 Correct 3 ms 4692 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 39 ms 5856 KB Output is correct
13 Correct 38 ms 5816 KB Output is correct
14 Correct 27 ms 5744 KB Output is correct
15 Correct 4 ms 4692 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 39 ms 5840 KB Output is correct
18 Correct 42 ms 5716 KB Output is correct
19 Correct 22 ms 5460 KB Output is correct
20 Correct 7 ms 4688 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5852 KB Output is correct
2 Correct 4 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 5588 KB Output is correct
5 Correct 2 ms 4692 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 27 ms 5856 KB Output is correct
8 Correct 9 ms 5596 KB Output is correct
9 Correct 4 ms 5460 KB Output is correct
10 Correct 3 ms 4692 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 39 ms 5856 KB Output is correct
13 Correct 38 ms 5816 KB Output is correct
14 Correct 27 ms 5744 KB Output is correct
15 Correct 4 ms 4692 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 39 ms 5840 KB Output is correct
18 Correct 42 ms 5716 KB Output is correct
19 Correct 22 ms 5460 KB Output is correct
20 Correct 7 ms 4688 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Execution timed out 1095 ms 128680 KB Time limit exceeded
23 Halted 0 ms 0 KB -