Submission #945232

# Submission time Handle Problem Language Result Execution time Memory
945232 2024-03-13T14:46:29 Z LucaIlie Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 248784 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 500;
const int MAX_K = 5000;
char mat[MAX_N + 2][MAX_N + 2];
set <pair <int, int>> dp[MAX_K];
int dl[4] = { -1, 0, 1, 0 };
int dc[4] = { 0, -1, 0, 1 };
int dir[256];

int main() {
    int n, m, k;

    dir['N'] = 0;
    dir['W'] = 1;
    dir['S'] = 2;
    dir['E'] = 3;

    cin >> n >> m >> k;
    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ )
            cin >> mat[l][c];
    }
    for ( int l = 0; l <= n + 1; l++ )
        mat[l][0] = mat[l][m + 1] = '#';
    for ( int c = 0; c <= m + 1; c++ )
        mat[0][c] = mat[n + 1][c] = '#';

    string moves;
    cin >> moves;
    moves = " " + moves;

    for ( int l = 1; l <= n; l++ ) {
        for ( int c = 1; c <= m; c++ ) {
            if ( mat[l][c] == '.' )
                dp[0].insert( { l, c } );
        }
    }
    for ( int i = 1; i <= k; i++ ) {
        for ( pair <int, int> p: dp[i - 1] ) {
            if ( moves[i] == '?' ) {
                for ( int d = 0; d < 4; d++ ) {
                    int l = p.first + dl[d], c = p.second + dc[d];
                    if ( mat[l][c] == '.' )
                        dp[i].insert( { l, c } );
                }
            } else {
                int d = dir[moves[i]];
                int l = p.first + dl[d], c = p.second + dc[d];
                if ( mat[l][c] == '.' )
                    dp[i].insert( { l, c } );
            }
        }
    }
    

    cout << dp[k].size();

    return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:50:37: warning: array subscript has type 'char' [-Wchar-subscripts]
   50 |                 int d = dir[moves[i]];
      |                                     ^
# Verdict Execution time Memory Grader output
1 Correct 103 ms 42680 KB Output is correct
2 Correct 7 ms 3420 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 42680 KB Output is correct
2 Correct 7 ms 3420 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 176 ms 47020 KB Output is correct
8 Correct 36 ms 9040 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 277 ms 47884 KB Output is correct
13 Correct 177 ms 35412 KB Output is correct
14 Correct 99 ms 22352 KB Output is correct
15 Correct 5 ms 1884 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 393 ms 48016 KB Output is correct
18 Correct 232 ms 38736 KB Output is correct
19 Correct 77 ms 17108 KB Output is correct
20 Correct 22 ms 6484 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 42680 KB Output is correct
2 Correct 7 ms 3420 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 176 ms 47020 KB Output is correct
8 Correct 36 ms 9040 KB Output is correct
9 Correct 7 ms 2652 KB Output is correct
10 Correct 2 ms 1116 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 277 ms 47884 KB Output is correct
13 Correct 177 ms 35412 KB Output is correct
14 Correct 99 ms 22352 KB Output is correct
15 Correct 5 ms 1884 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 393 ms 48016 KB Output is correct
18 Correct 232 ms 38736 KB Output is correct
19 Correct 77 ms 17108 KB Output is correct
20 Correct 22 ms 6484 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Execution timed out 1077 ms 248784 KB Time limit exceeded
23 Halted 0 ms 0 KB -