#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <type_traits>
#include <string>
#include <queue>
#define ll long long
#include <map>
using namespace std;
vector<string> vec;
bool okay (int i, int j) {
if (i < 0 || j < 0 || i >= vec.size() || j >= vec[0].size()) {
return false;
}
if (vec[i][j] == '#') {
return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
set<pair<int,int>> pos;
int R, C, M;
cin >> R >> C >> M;
vec.resize(R);
for (int i = 0; i < R; i++) {
cin >> vec[i];
assert(vec[i].size() == C);
}
string s;
cin >> s;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (vec[i][j] != '#') {
pos.insert({i, j});
}
}
}
map<char,pair<int,int>> myMap;
myMap['W'] = {0, -1};
myMap['E'] = {-1, 0};
myMap['N'] = {0, 1};
myMap['S'] = {1, 0};
for (int i = 0; i < s.length(); i++) {
set<pair<int,int>> valid;
for (char c: {'W', 'N', 'S', 'E'}) {
if (s[i] == c || s[i] == '?') {
for (auto& p: pos) {
if (p.first + myMap[c].first >= 0 && p.second + myMap[c].second >= 0
&& p.first + myMap[c].first < R && p.second + myMap[c].second < C
&& vec[p.first + myMap[c].first][p.second + myMap[c].second] == '.') {
valid.insert({p.first + myMap[c].first, p.second + myMap[c].second});
}
}
}
}
pos = valid;
//for (auto& p: pos) {
//cout << p.first << " " << p.second << '\n';
//}
//cout << '\n';
//cout << '\n';
}
for (auto& p: pos) {
//cout << p.first << " " << p.second << '\n';
}
cout << pos.size() << '\n';
}
Compilation message
nautilus.cpp: In function 'bool okay(int, int)':
nautilus.cpp:21:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (i < 0 || j < 0 || i >= vec.size() || j >= vec[0].size()) {
| ~~^~~~~~~~~~~~~
nautilus.cpp:21:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (i < 0 || j < 0 || i >= vec.size() || j >= vec[0].size()) {
| ~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from nautilus.cpp:7:
nautilus.cpp: In function 'int main()':
nautilus.cpp:38:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
38 | assert(vec[i].size() == C);
| ~~~~~~~~~~~~~~^~~~
nautilus.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 0; i < s.length(); i++) {
| ~~^~~~~~~~~~~~
nautilus.cpp:74:16: warning: unused variable 'p' [-Wunused-variable]
74 | for (auto& p: pos) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
151 ms |
1260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
151 ms |
1260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
151 ms |
1260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |