Submission #921420

# Submission time Handle Problem Language Result Execution time Memory
921420 2024-02-03T20:02:09 Z aykhn Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 4440 KB
#include <bits/stdc++.h>
 
// author: aykhn

using namespace std;

#define int long long
#define inf 0x3F3F3F3F

const int MXN = 5e2 + 5;

int n, m, K;
char mat[MXN][MXN];
string s;

int A[4] = {0, 0, -1, 1};
int B[4] = {-1, 1, 0, 0};
int C[26], D[26];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    C['S' - 'A'] = -1;
    D['S' - 'A'] = 0;
    C['N' - 'A'] = 1;
    D['N' - 'A'] = 0;
    C['W' - 'A'] = 0;
    D['W' - 'A'] = 1;
    C['E' - 'A'] = 0;
    D['E' - 'A'] = -1;
    cin >> n >> m >> K;
    vector<vector<int>> dp(n, vector<int> (m, 0)), ndp;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++) 
        {
            cin >> mat[i][j];
            dp[i][j] = (mat[i][j] != '#');
        }
    }
    cin >> s;
    s = "#" + s;
    int res;
    for (int k = 1; k <= K; k++)
    {
        ndp.assign(n, vector<int> (m, 0));
        res = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (mat[i][j] == '#') continue;
                if (s[k] == '?')
                {
                    for (int l = 0; l < 4; l++)
                    {
                        int x = i + A[l], y = j + B[l];
                        if (x >= 0 && x < n && y >= 0 && y < m) ndp[i][j] |= dp[x][y];
                    }
                }
                else
                {
                    int x = i + C[s[k] - 'A'], y = j + D[s[k] - 'A'];
                    if (x >= 0 && x < n && y >= 0 && y < m) ndp[i][j] |= dp[x][y];
                }
                res += ndp[i][j];
            }
        }
        dp = ndp;
    }
    cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 5 ms 600 KB Output is correct
8 Correct 7 ms 684 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 10 ms 600 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 8 ms 604 KB Output is correct
18 Correct 10 ms 604 KB Output is correct
19 Correct 7 ms 856 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 5 ms 600 KB Output is correct
8 Correct 7 ms 684 KB Output is correct
9 Correct 6 ms 600 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 8 ms 600 KB Output is correct
14 Correct 10 ms 600 KB Output is correct
15 Correct 4 ms 604 KB Output is correct
16 Correct 2 ms 676 KB Output is correct
17 Correct 8 ms 604 KB Output is correct
18 Correct 10 ms 604 KB Output is correct
19 Correct 7 ms 856 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 2 ms 600 KB Output is correct
22 Execution timed out 1030 ms 4440 KB Time limit exceeded
23 Halted 0 ms 0 KB -