Submission #1021841

# Submission time Handle Problem Language Result Execution time Memory
1021841 2024-07-13T06:02:28 Z basa Nautilus (BOI19_nautilus) C++14
66 / 100
44 ms 41564 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

string m;
int r, c, k;
string s[105];
bool vis[105][105][5005];

int dfs(int i, int j, int p){
  if(i >= r || i < 0) return 0;
  if(j >= c || j < 0) return 0;
  if(s[i][j] == '#') return 0;
  if(vis[i][j][p]) return 0;
  vis[i][j][p] = 1;
  if(p == m.size()) return 1;


  int ret = 0;

  if(m[p] == 'N') ret = dfs(i - 1, j, p + 1);
  if(m[p] == 'S') ret = dfs(i + 1, j, p + 1);
  if(m[p] == 'E') ret = dfs(i, j + 1, p + 1);
  if(m[p] == 'W') ret = dfs(i, j - 1, p + 1);

  if(m[p] == '?'){
    ret += dfs(i + 1, j, p + 1);
    ret += dfs(i - 1, j, p + 1);
    ret += dfs(i, j + 1, p + 1);
    ret += dfs(i, j - 1, p + 1);
  }

  return ret;
}

signed main()
{
  cin.tie(0) -> sync_with_stdio(0);
  cin >> r >> c >> k;

  for(int i = 0; i < r; i++) cin >> s[i];

  cin >> m;

  int ans = 0;
  for(int i = 0; i < r; i++){
    for(int j = 0; j < c; j++){
      if(s[i][j] == '#') continue;
      ans += dfs(i, j, 0);
    }
  }

  cout << ans;
}

Compilation message

nautilus.cpp: In function 'long long int dfs(long long int, long long int, long long int)':
nautilus.cpp:18:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   if(p == m.size()) return 1;
      |      ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 41308 KB Output is correct
2 Correct 14 ms 32432 KB Output is correct
3 Correct 10 ms 24532 KB Output is correct
4 Correct 7 ms 16928 KB Output is correct
5 Correct 4 ms 8792 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 41308 KB Output is correct
2 Correct 14 ms 32432 KB Output is correct
3 Correct 10 ms 24532 KB Output is correct
4 Correct 7 ms 16928 KB Output is correct
5 Correct 4 ms 8792 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 32 ms 41564 KB Output is correct
8 Correct 15 ms 25044 KB Output is correct
9 Correct 7 ms 16732 KB Output is correct
10 Correct 4 ms 8792 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 40 ms 41512 KB Output is correct
13 Correct 35 ms 33364 KB Output is correct
14 Correct 23 ms 24924 KB Output is correct
15 Correct 4 ms 8724 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 44 ms 41464 KB Output is correct
18 Correct 38 ms 33492 KB Output is correct
19 Correct 12 ms 17024 KB Output is correct
20 Correct 5 ms 8796 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 41308 KB Output is correct
2 Correct 14 ms 32432 KB Output is correct
3 Correct 10 ms 24532 KB Output is correct
4 Correct 7 ms 16928 KB Output is correct
5 Correct 4 ms 8792 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 32 ms 41564 KB Output is correct
8 Correct 15 ms 25044 KB Output is correct
9 Correct 7 ms 16732 KB Output is correct
10 Correct 4 ms 8792 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 40 ms 41512 KB Output is correct
13 Correct 35 ms 33364 KB Output is correct
14 Correct 23 ms 24924 KB Output is correct
15 Correct 4 ms 8724 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 44 ms 41464 KB Output is correct
18 Correct 38 ms 33492 KB Output is correct
19 Correct 12 ms 17024 KB Output is correct
20 Correct 5 ms 8796 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Runtime error 2 ms 856 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -