Submission #529620

#TimeUsernameProblemLanguageResultExecution timeMemory
529620schseNautilus (BOI19_nautilus)C++17
66 / 100
20 ms1604 KiB
#include <bits/stdc++.h>
using namespace std;
 
bool been[102][102][102];
bool lastpos[502][502];
 
string dirs;
vector<vector<bool>> field;
 
void dfs(int n, int x, int y)
{
    if (been[n][x][y])
        return;
    if (!field[y][x])
        return;
    if (n == dirs.size())
    {
        lastpos[y][x] = true;
        return;
    }
    been[n][x][y] = true;
    if (dirs[n] == 'N')
         dfs(n + 1, x, y - 1);
    else if (dirs[n] == 'S')
         dfs(n + 1, x, y + 1);
    else if (dirs[n] == 'W')
         dfs(n + 1, x - 1, y);
    else if (dirs[n] == 'E')
         dfs(n + 1, x + 1, y);
    else
    {
        dfs(n + 1, x, y - 1);
        dfs(n + 1, x, y + 1);
        dfs(n + 1, x - 1, y);
        dfs(n + 1, x + 1, y);
    }
}
 
int main()
{
    int R, C, M;
    cin >> R >> C >> M;
    field.resize(R + 2, vector<bool>(C + 2, 0));
    for (int i = 0; i < R; i++)
    {
        string str;
        cin >> str;
        for (int e = 0; e < str.size(); e++)
            field[i + 1][e + 1] = str[e] == '.';
    }
    cin >> dirs;
    int sum = 0;
    for (int x = 0; x < C; x++)
        for (int y = 0; y < R; y++)
            dfs(0, x + 1, y + 1);
 
    sum = 0;
    for (int x = 0; x < C; x++)
    {
        for (int y = 0; y < R; y++)
        {
            if (lastpos[y + 1][x + 1])
                sum++;
        }
    }
    cout << sum;
    return 0;
}

Compilation message (stderr)

nautilus.cpp: In function 'void dfs(int, int, int)':
nautilus.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if (n == dirs.size())
      |         ~~^~~~~~~~~~~~~~
nautilus.cpp: In function 'int main()':
nautilus.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int e = 0; e < str.size(); e++)
      |                         ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...