이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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;
set<pair<int,int>> orig;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (vec[i][j] == '.') {
pos.insert({i, j});
}
}
}
orig = pos;
map<char,pair<int,int>> myMap;
myMap['W'] = {0, -1};
myMap['E'] = {0, 1};
myMap['S'] = {1, 0};
myMap['N'] = {-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] == '?') {
set<pair<int,int>> new_pos;
for (auto& p: pos) {
int dx = p.first + myMap[c].first;
int dy = p.second + myMap[c].second;
new_pos.insert({dx, dy});
}
vector<pair<int,int>> res;
set_intersection(new_pos.begin(), new_pos.end(), orig.begin(), orig.end(), std::back_inserter(res));
for (auto& p: res) {
valid.insert(p);
}
}
}
pos = valid;
}
cout << pos.size() << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
In file included from /usr/include/c++/10/cassert:44,
from nautilus.cpp:7:
nautilus.cpp: In function 'int main()':
nautilus.cpp:29:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
29 | assert(vec[i].size() == C);
| ~~~~~~~~~~~~~~^~~~
nautilus.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < s.length(); i++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |